In the following code, I have created a template and am creating Views of 
the template and inserting the view in the ViewContainer whenever a button 
is clicked. On clicking the template's view, the view should be deleted 
from the ViewContainer.


https://stackblitz.com/edit/angular-bqm11b


The issue I am facing is I am unable to figure out how to delete the 
correct view. As the handler for (click) is in the template itself (which 
could be a wrong approach I admit and thus am open to suggestions), I want 
to know at which index this view is stored so that I can pass that 
information to the handler. But it seems that passing index to 
createEmbeddedView isn't working as I expected.


I create 4 views by clicking the button 4 times. The index are 0,1,2,3. Now 
I delete view 2 (index 1). On clicking the button again, I want to create 
the view at index 4 (even though I know that index 1 is empty). But it 
seems that the ViewContainer rearranges the indexes of views once a view is 
deleted and inserts the next view at index 3. (see the prints in the 
console window)


1) Is it the index no. specified has to be less than or equal to the size 
of the view container? 

2) How could I store information about which view is deleted at which index 
so that I can delete it from ViewContainer?

3) Is my approach correct or is there a better way (design pattern) to 
delete a specific view from ng-container


-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to