Let's say we have an array of items:
items = [
{ title: 'item 1'},
{ title: 'item 2'},
/* ... */
];
And there is a template that renders this array:
<ul>
<li *ngFor="let item of items">{{item.title}}</li>
</ul>
Wll angular2 rerender the whole array if I add/remove items via push
/splice
or will it only add/remove the markup for the corresponding items? If it does updates only, then is there any difference in mutation stategies -- should I prefer push/splice over array replacing? In other words, are these two approaches equivalent in term of rendering performance:
/* 1: mutation */
this.items.push({ title: 'New Item' });
/* 2: replacement */
var newArray = this.items.slice();
newArray.push({ title: 'New Item' });
this.items = newArray;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…