Angular 2 How to use ngfor Angular2 aliased exported values

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Angular2 provides several exported values that can be aliased to local variables. These are:

  • index
  • first
  • last
  • even
  • odd

Except index, the other ones take a Boolean value. As the previous example using index, it can be used any of these exported values:

<div *ngFor="let item of items; let firstItem = first; let lastItem = last">
  <p *ngIf="firstItem">I am the first item and I am gonna be showed</p>
  <p *ngIf="firstItem">I am not the first item and I will not show up :(</p>
  <p *ngIf="lastItem">But I'm gonna be showed as I am the last item :)</p>
</div>


Got any Angular 2 Question?