angular - 从构建中排除一些惰性模块(Angular5)
问题描述
我正在开发一个项目,该项目在多个客户中运行。有许多延迟加载的模块,其中大部分被所有客户使用。但是有些模块只在少数地方需要,所以我想将它们从其他地方的构建中排除。
可能吗?
解决方案
像这样的东西怎么样:(然后您可以使用 if 语句等来加载不同的模块)
export class AppComponent implements AfterViewInit {
@ViewChild('testOutlet', {read: ViewContainerRef}) testOutlet: ViewContainerRef;
constructor(
private loader: NgModuleFactoryLoader,
private injector: Injector) {
}
ngAfterViewInit(): void {
const path = 'src/app/lazy/lazy.module#LazyModule';
this.loader.load(path).then((moduleFactory: NgModuleFactory<any>) => {
const entryComponent = (<any>moduleFactory.moduleType).entry;
const moduleRef = moduleFactory.create(this.injector);
const compFactory = moduleRef.componentFactoryResolver.resolveComponentFactory(entryComponent);
this.testOutlet.createComponent(compFactory);
});
}
}
推荐阅读
- python - 下拉菜单无法使用 Kivy 语言
- python - 填写缺失的日期值并根据前一行填充第二列
- bazel - 如何通过“ctx.actions.run(...)”调试由 Bazel 规则执行的“java_binary”目标?
- python - 图像处理 剪切与图案不同的区域
- c# - 有人能告诉我为什么 (return DayName;) 会导致错误,因为它是一个未分配的局部变量吗?
- apache-kafka - Kafka 消费者向代理发送更多获取请求
- sql - 在 Where-In SQL-Oracle 中传递多个参数
- android - Kotlin 构造函数中的泛型
- regex - 匹配由单词边界包围的任何九位数字,但不匹配以句点开头的数字
- excel - VBA Vlookup 函数