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