I am trying to dynamically create and destroy components. Let's say I have a component A which has a button on click of which I create a component B using ComponentFactoryResolver. Now I am creating multiple instance of components by clicking on the button multiple times. My component B has an html something as the following:
<div id="container-{{index}}"
...more content
</div>
In my component B, I want to destroy some other instance of B which was created earlier. How can I get the reference to some other instance of B inside a new instance of B? Is it possible to somehow use the id of the underlying html to get the reference to the component?
@ViewChildren(BClassComponent) bComponentsList: BClassComponent [];you gonna have a reference to all B Components that you have in your A template. But I'm sure that there would be another cleaner option depends on your specific needs.