Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create addComponent method
import { Component } from '@angular/core';
import { DynamicComponent } from './dynamic.component';
selector: 'host',
templateUrl: './host.component.html',
styleUrls: [ './host.component.css' ],
entryComponents: [DynamicComponent]
export class AppComponent {
@ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef;
constructor (private resolver: ComponentFactoryResolver) {
addComponent() {
let factory = this.resolver.resolveComponentFactory(DynamicComponent);
let component = factory.create(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment