@Component({ | |
selector: 'app', | |
template: `<ul> | |
<li *ngFor="let item of items; trackBy: trackById">{{item.name}}</li> | |
</ul>` | |
}) | |
class AppComponent { | |
Items = [ | |
{ | |
id: 1, | |
name: 'item 1' | |
}, { | |
id: 2, | |
name: 'item 2' | |
}, | |
... | |
]; | |
trackById(index, item) { | |
return item.id; | |
} | |
} |