Не найдена фабрика компонентов для класса {constructor () {this.iterablePlainMap = e.message} ngOnInit () {}}. Вы добавили его в @ NgModule.entryComponents? - PullRequest
0 голосов
/ 05 марта 2020

Работает нормально с ng serve, но выдает эту ошибку после ng build ---prod

Это класс компонентов, в котором я создаю динамический c компонент во время выполнения component.ts

   dynamicComponent;
   dynamicModule: NgModuleFactory<any>;

   downloadFile() {
      this.http.get(this.fileUrl, { responseType: 'text' }).subscribe(res => {
      this.dynamicComponent = this.createNewComponent(res);
      this.dynamicModule=this.compiler.compileModuleSync(this.createComponentModule(this.dynamicComponent));
    });
   }

Создать новую функцию модуля

 protected createComponentModule(componentType: any) {
    @NgModule({
      imports: [
        FormsModule,
        CommonModule
      ],
      declarations: [
        componentType,
      ],
      entryComponents: [componentType]
    })
    class RuntimeComponentModule {
    }
    // a module for just this Type
    return RuntimeComponentModule;
  }

Создать новую функцию компонента

 protected createNewComponent(text: string) {
    const that = this;
    @Component({
      selector: 'dynamic-component',
      template: `${text}`,
      interpolation: ['{[{', '}]}']
    })
    class DynamicComponent implements OnInit {
      ngOnInit() {
      }
    }
    return DynamicComponent;
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...