下面是我的创建动态模块的初始代码:
protected createComponentModule(componentType: any) {
@NgModule({
imports: [
ComponentModule
],
declarations: [
componentType
],
})
class RuntimeComponentModule {
}
return RuntimeComponentModule;
}
虽然我打算在下面的代码中实现AOT,但它抛出了错误:
No NgModule metadata found for 'RuntimeComponentModule'
我通过更改下面的代码找到了一些 Articals 的解决方案,我的错误消失了:
default class RuntimeComponentModule
{
}
但是它引发了新的错误:
Modifiers cannot appear here
它不允许我在方法内装饰@NgModule。
最佳答案
使用动态组件或模块创建目前官方不支持与AoT一起使用
参见 https://github.com/angular/angular/issues/11780 的讨论寻找可能的解决方法。
关于 Angular 2 : Dynamic component creation : AOT Compilation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42551380/