Angular2 : Dynamic component creation : AOT Compilation

馋奶兔 提交于 2019-11-30 14:01:34

问题


Below is my initial code to create dynamic module:

protected createComponentModule(componentType: any) {

    @NgModule({
        imports: [
            ComponentModule 
        ],
        declarations: [
            componentType
        ],
    })
    class RuntimeComponentModule {
    }
    return RuntimeComponentModule;

}

While I am going to implement AOT on below code it throw me error:

No NgModule metadata found for 'RuntimeComponentModule'

I found solution of it some Articals by change below code and my error gone away:

default class RuntimeComponentModule 
{
}

But new error is raised it say:

Modifiers cannot appear here

It not allowed me to decorate @NgModule within method.


回答1:


Using dynamic component or module creation is currently not officially supported to be used together with AoT

See the discussion at https://github.com/angular/angular/issues/11780 for possible workarounds.



来源:https://stackoverflow.com/questions/42551380/angular2-dynamic-component-creation-aot-compilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!