title: Angular2 - ngFor trackby index without custom function
body: <p>I want to use ngFor trackBy index. And I find some way like below</p>
  
  <pre><code>@Component({
    selector: 'my-app',
    template: `
      &lt;ul&gt;
        &lt;li *ngFor="let item of collection;trackBy: trackByFn"&gt;{{item.id}}&lt;/li&gt;
      &lt;/ul&gt;
      &lt;button (click)="getItems()"&gt;Refresh items&lt;/button&gt;
    `,
  })
  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
    }
  }
  </code></pre>
  
  <p>But all the way I found need to create a function in component class.</p>
  
  <p>I try these but seem to not work:</p>
  
  <pre><code>*ngFor="let item of collection; trackBy:index"
  
  *ngFor="let item of collection; let i = index; trackBy:i"
  </code></pre>
  
  <p>Is there any way to track by index without custom function?</p>
  
  <p>Thanks for any answer!</p>