2017-03-02 121 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

我也这么认为,我已经尝试了很多方法,但是没有运气 –