本文介绍了Angular2:动态组件创建:AOT编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的用于创建动态模块的初始代码:
protected createComponentModule(componentType: any) {
@NgModule({
imports: [
ComponentModule
],
declarations: [
componentType
],
})
class RuntimeComponentModule {
}
return RuntimeComponentModule;
}
虽然我要在以下代码上实现 AOT ,但会抛出错误:
While I am going to implement AOT on below code it throw me error:
通过以下代码的更改,我找到了一些Articals解决方案,而我的错误消失了:
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:
不允许我在方法中装饰@NgModule.
It not allowed me to decorate @NgModule within method.
推荐答案
目前尚不正式支持将动态组件或模块创建与AoT一起使用
Using dynamic component or module creation is currently not officially supported to be used together with AoT
请参阅 https://github.com/angular/angular/issues/11780 了解可能的解决方法.
See the discussion at https://github.com/angular/angular/issues/11780 for possible workarounds.
这篇关于Angular2:动态组件创建:AOT编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!