angular - 找不到类{constructor(){this.iterablePlainMap=e.message}ngOnInit(){}} 的组件工厂。你把它添加到@NgModule.entryComponents 了吗?
问题描述
它可以正常工作,ng serve
但之后会出现此错误ng build ---prod
这是组件类,我在运行时 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;
}
解决方案
推荐阅读
- node.js - node.js 对 Nightwatchjs 意味着什么?
- spring-security - java安全框架的优势是什么?
- html - 如何在自定义产品选项卡中显示 Shopify 的页面文本
- php - 如何从 Explode 中获取数据并检查是否相同的数据
- python - 如何自动重启python来修复内存泄漏?
- null - Acumatica AP301000GetSchema 返回 null
- database - 使用 DokuWiki,当用户创建新页面时如何将一些信息记录到我的数据库中
- vba - 从表格中获取输入并将其格式化为称呼、首字母和姓氏
- mysql - MySql 部分总和
- json - 对 api 的 ajax 请求成功,但会触发错误事件