I’m using *ngFor inside a page template (Ionic 2 beta 7).
<div class="child" *ngFor="let child of children">
...
</div>
{{children.length}}
I update the children array when changes are detected (add, update, remove). I do this using ‘push’ and ‘splice’.
When an item is added or updated inside the array, the ngFor is triggered and the DOM is updated. However, when an item is removed, the array is changed, but the DOM does not remove the entry for that item.
The {{children.length}} also does not get updated when removing an item. It does when adding or updating.
I’ve also tried to replace the entire array with a new array. The same thing happens, adding and removing works fine, removing not.
Yes I am sure.
The array has 0 items, however the DOM still contains one or more items.
I’ve also seen similar behaviour with ion-slides.
I generate the slides using ngFor, based on an array.
When I update a slide, no problem. But when I try to remove a slide, nothing happens.
I recommend you read about ngZone. It’s not simply explain it and my English isn’t very good for this. But it was zonejs who decides when to update the DOM.
PS I never used it
I have experimented some more, using NgZone and even by completely reconstructing the array from scratch, but the DOM is still not updating… weird behaviour -_-
@csysmans In case that you updated your project from an earlier version of the framework I would suggest to check if you performed the update properly. If you missed something by the update, it might result in such a weird behavior. Check out the following post for more details: