Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created May 19, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniele-zurico/3e35f14784b65aafe7853d6e8df4f2f9 to your computer and use it in GitHub Desktop.
Save daniele-zurico/3e35f14784b65aafe7853d6e8df4f2f9 to your computer and use it in GitHub Desktop.
app.component.ts
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);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment