2017-03-02 123 views
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。

+0

你可以參考這個鏈接。 http://stackoverflow.com/questions/38888008/how-can-i-use-create-dynamic-template-to-compile-dynamic-component-with-angular –

+1

@Karan:沒有運氣,我已經試過了 –

+0

@Karan Patel,已經提到這個鏈接。但與AOT它不起作用。 – Darshita

回答

1

使用動態組件或模塊創建目前不正式支持要與AOT

一起使用,請參閱https://github.com/angular/angular/issues/11780爲可能的解決方法的討論。

+0

我也這麼認爲,我已經嘗試了很多方法,但是沒有運氣 –