Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created November 9, 2016 15:02
Show Gist options
  • Save NetanelBasal/099f5c45ffbe6b573b65abe6413ec519 to your computer and use it in GitHub Desktop.
Save NetanelBasal/099f5c45ffbe6b573b65abe6413ec519 to your computer and use it in GitHub Desktop.
@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