【问题标题】:Angular2 : Dynamic component creation : AOT CompilationAngular2:动态组件创建:AOT 编译
【发布时间】:2017-07-21 22:34:06
【问题描述】:

下面是我的创建动态模块的初始代码

protected createComponentModule(componentType: any) {

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

}

虽然我要在下面的代码上实现 AOT,但它会抛出错误:

找不到“RuntimeComponentModule”的 NgModule 元数据

我通过更改以下代码找到了一些 Articals 的解决方案,并且我的错误消失了:

default class RuntimeComponentModule 
{
}

但是出现了新的错误,它说:

修饰符不能出现在这里

它不允许我在方法中装饰@NgModule。

【问题讨论】:

标签: angular angular2-aot ng-modules


【解决方案1】:

目前官方不支持使用动态组件或模块创建与AoT一起使用

有关可能的解决方法,请参阅https://github.com/angular/angular/issues/11780 的讨论。

【讨论】:

  • 我也这么认为,我已经尝试了很多方法但没有运气
猜你喜欢
  • 2018-05-31
  • 2017-10-10
  • 1970-01-01
  • 2017-04-05
  • 1970-01-01
  • 1970-01-01
  • 2017-04-01
  • 1970-01-01
  • 2017-11-01
相关资源
最近更新 更多