DYNAMIC COMPONENTS
➤ Where is the component inserted?
➤ How is it instantiated?
@Component({
template: `
`
})
export class HomeComponent {
@ViewChild('vc', { read: ViewContainerRef }) vc;
constructor(
private injector: Injector,
private cfr: ComponentFactoryResolver) {}
addDynamicComponent() {
const cmpFactory = this.cfr.resolveComponentFactory(NoteComponent);
const componentRef = cmpFactory.create(this.injector);
this.vc.insert(componentRef.hostView);
}