13
下面是我最初的代码来创建动态模块:Angular2:动态组件创建:AOT编译
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。
你可以参考这个链接。 http://stackoverflow.com/questions/38888008/how-can-i-use-create-dynamic-template-to-compile-dynamic-component-with-angular –
@Karan:没有运气,我已经试过了 –
@Karan Patel,已经提到这个链接。但与AOT它不起作用。 – Darshita