angular - Angular:在根模块中加载 JIT 编译的动态模块
问题描述
我生成了一个 JIT 编译模块,但无法将它加载到根模块中。任何帮助将不胜感激..这是我解决这个问题的第三天
JIT 编译模块 - dynaModule
let dynaModule = NgModule({
declarations: dyna_comps,
exports: dyna_comps,
imports: [CommonModule, RouterModule.forChild([
{
path: 'cc1',
component: dyna_comps[0]
},
{
path: 'cc2',
component: dyna_comps[1]
}
]),
],
providers: [GlobalService], //- e.g.if your dynamic component needs any service, provide it here.
})(class { });
this.compiler.compileModuleAndAllComponentsAsync(dynaModule)
.then((factories) => {
for (let i = 0; i < factories.componentFactories.length; i++)
{
const f = factories.componentFactories[i];
this.cmpRef = f.create(this.injector, [], null, this.moduleRef);
this.cmpRef.instance.name = 'DCOMP' + i;
}
});
对于静态模块,我可以使用 router.resetConfig 方法延迟加载它
this.router.resetConfig([
...this.router.config,
{
path: 'c',
loadChildren: '../static/static.module#StaticModule'
}
]);
如何在根模块中加载这个 JIT compile dynaModule 以便完成路由?
解决方案
推荐阅读
- telegram - 在 Telegram 中检查关键字
- python-3.x - 在 Django 中,如何编写一个查询来按一周中的特定日期过滤日期列?
- python - 如何在pyqt5中保存绘制的蒙版
- python - python反向字符串::-1切片函数等价
- ruby-on-rails - 如何使用 Devise::FailureApp 来捕获失败的登录尝试
- django - 模型更改后如何迁移 django 数据库?
- konvajs - 如何使用 KanvaJS 在复杂绘图的开始和结束时触发事件的正确方法是什么?
- firebase-hosting - 如何在没有任何公共目录的情况下将所有请求重定向到 Function 或 Cloud Run 服务?
- java - 在我的基于 Spring Boot 的项目中不连接 css 文件
- javascript - Javascript 事件监听函数绑定