angular/integration/dynamic-compiler/src/app.component.ts
Matthieu Riegler e85021a7ba build: Migrate all integration tests with the schematic. (#58160)
All components, directives and pipes will now use standalone as default. Non-standalone decorators have now .

PR Close #58160
2024-10-14 14:58:58 +00:00

24 lines
689 B
TypeScript

import {AfterViewInit, Compiler, Component, ViewChild, ViewContainerRef} from '@angular/core';
@Component({
selector: 'app-root',
template: `
<h1>Hello world!</h1>
<div #vc></div>
`,
standalone: false,
})
export class AppComponent implements AfterViewInit {
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef;
constructor(private compiler: Compiler) {}
ngAfterViewInit() {
import('./lazy.module').then((module) => {
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule).then((compiled) => {
const factory = compiled.componentFactories[0];
this.container.createComponent(factory);
});
});
}
}