title: Angular efficiently using trackBy with ngFor
body: <p>In Angular, is the trackBy function necessary for *ngFor? I saw a few articles <a href="https://github.com/mgechev/angular-performance-checklist" rel="noreferrer">here</a>, <a href="https://medium.com/paramsingh-66174/catalysing-your-angular-4-app-performance-9211979075f6" rel="noreferrer">here</a>, <a href="http://niisar.blogspot.com/2017/02/improving-angular-2-performance-in-ngfor.html" rel="noreferrer">here</a>, and <a href="http://www.talkinghightech.com/en/angular-2-imporve-ngfor-preformance/" rel="noreferrer">here</a> that say using trackBy will improve performance and has better memory management. But I was wondering if trackBy is such an improvement, then why isn't it default behavior? Is it default behavior and everything I am looking at is out of date? </p>
  
  <p>If it isn't default behavior, my project has about 90 *ngFor in 90 components and I was wondering if there was a way to use the trackBy where I am not including the following function 90 times. I also want to avoid adding a service and importing that 90 times.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;mat-option *ngFor="let l of list; trackBy: trackByFn" [value]="l.id"&gt;
     {{l.name}}
  &lt;/mat-option&gt;
  </code></pre>
  
  <p><strong>TS</strong></p>
  
  <pre><code>trackByFn(index, item) {
      return index
  }
  </code></pre>