1

I want to create a modal component dynamically and append the component to the body or my root element.

I know that when you need to add component dynamically you need a ViewContainerRef.

For example:

createComponent(type) {
    this.container.clear(); 
    const factory: ComponentFactory = this.resolver.resolveComponentFactory(AlertComponent);
    this.componentRef: ComponentRef = this.container.createComponent(factory);
  }

How to append the component to the root component?

ng2user
  • 1,807
  • 5
  • 19
  • 28

1 Answers1

0

You should use the selector in your the rootcomponent html file