在你的Angular应用程序中,建议使用“angular - cli”构建和打包,以确保在构建时包含所有必需的依赖项。如果你仍然无法加载动态组件,则可能是因为您没有正确的aot配置,可以尝试如下方法:
在根模块中导入NgModule,为JIT编译器添加此导入即可。
import { NgModule } from '@angular/core';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
// import the dynamic component module
DynamicComponentModule,
// add the following lines of code
// import the JIT compiler module
// and set the compiler as compile-time dependency
// for the dynamic component module
CompilerModule.forRoot({
useClass: JitCompiler
})
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
提示:以上示例仅为参考,不可以完全复制粘贴使用,需要根据自己的实际情况进行修改。