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?