I am using this to dynamically create a component in angular:
addComponent() {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(ChildComponent);
const viewContainerRef = this.injectComp.viewContainerRef;
const compRef = viewContainerRef.createComponent(componentFactory);
compRef.instance.someProperty = "some data";
}
So each time the method is executed a new instance of the component is created. Up to there, all is great but my question is:
How do I destroy these created components from the ChildComponent itself with a button click event?