2017-11-15 17:22:23 +00:00
|
|
|
import {AfterViewInit, Compiler, Component, ViewChild, ViewContainerRef} from '@angular/core';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-root',
|
|
|
|
|
template: `
|
|
|
|
|
<h1>Hello world!</h1>
|
|
|
|
|
<div #vc></div>
|
|
|
|
|
`,
|
|
|
|
|
})
|
|
|
|
|
export class AppComponent implements AfterViewInit {
|
2019-10-05 08:04:54 +00:00
|
|
|
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef;
|
2017-11-15 17:22:23 +00:00
|
|
|
|
2019-05-23 18:31:10 +00:00
|
|
|
constructor(private compiler: Compiler) {}
|
2017-11-15 17:22:23 +00:00
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2021-09-27 10:18:09 +00:00
|
|
|
import('./lazy.module').then(module => {
|
2019-05-23 18:31:10 +00:00
|
|
|
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule).then((compiled) => {
|
|
|
|
|
const factory = compiled.componentFactories[0];
|
|
|
|
|
this.container.createComponent(factory);
|
|
|
|
|
});
|
2017-11-15 17:22:23 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|