I am creating a component at runtime using ComponentFactoryResolver.
This method adds the component
addComp(): void {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(OneComponent);
const viewContainerRef = this.injectComp.viewContainerRef;
viewContainerRef.createComponent(componentFactory);
}
And this method delete's a component
removeComp(): void {
const viewContainerRef = this.injectComp.viewContainerRef;
viewContainerRef.remove();
}
The issue I'm having is that I need to be able to tell it which component I want to remove as it seems to just delete each component in the order it's created.
How can I modify the removeComp()
method so that I can define the component that I want to remove?