Created
November 9, 2016 15:02
-
-
Save NetanelBasal/099f5c45ffbe6b573b65abe6413ec519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'my-app', | |
template: ` | |
<ul> | |
<li *ngFor="let item of collection;trackBy: trackByFn">{{item.id}}</li> | |
</ul> | |
<button (click)="getItems()">Refresh items</button> | |
`, | |
}) | |
export class App { | |
constructor() { | |
this.collection = [{id: 1}, {id: 2}, {id: 3}]; | |
} | |
getItems() { | |
this.collection = this.getItemsFromServer(); | |
} | |
getItemsFromServer() { | |
return [{id: 1}, {id: 2}, {id: 3}, {id: 4}]; | |
} | |
trackByFn(index, item) { | |
return index; // or item.id | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment