简体   繁体   English

Angular2:动态组件创建:AOT编译

[英]Angular2 : Dynamic component creation : AOT Compilation

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: 虽然我将在下面的代码上实现AOT ,但它会给我一个错误:

No NgModule metadata found for 'RuntimeComponentModule' 找不到'RuntimeComponentModule'的NgModule元数据

I found solution of it some Articals by change below code and my error gone away: 我通过更改下面的代码找到了一些Articals的解决方案,我的错误消失了:

default class RuntimeComponentModule 
{
}

But new error is raised it say: 但是它提出了新的错误:

Modifiers cannot appear here 修饰符不能出现在这里

It not allowed me to decorate @NgModule within method. 它不允许我在方法中装饰@NgModule。

Using dynamic component or module creation is currently not officially supported to be used together with AoT 目前,官方不支持使用动态组件或模块创建与AoT一起使用

See the discussion at https://github.com/angular/angular/issues/11780 for possible workarounds. 有关可能的解决方法,请参阅https://github.com/angular/angular/issues/11780上的讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM