Created
May 19, 2018 16:37
-
-
Save daniele-zurico/3e35f14784b65aafe7853d6e8df4f2f9 to your computer and use it in GitHub Desktop.
app.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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