我正在处理一个项目,该项目在多个客户处运行。有很多惰性加载模块,其中大部分被所有客户使用。但是有些模块只在少数地方需要,所以我想将它们排除在其他地方的构建之外。
这可能吗?
最佳答案
这样的事情怎么样: (然后您可以使用 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);
});
}
}
关于angular - 从构建中排除一些惰性模块(Angular5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50511553/