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