I am working on a project, which runs at multiple customers. There are many lazy loaded modules, and most of them is used by all of the customers. But there are some modules, which are only needed in a few places, so I would like to exclude them from the build everywhere else.
Is it possible?
How about something like this: (you could then use if statements, etc, to load different modules)
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);
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With