Работает нормально с 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;
}