Angular *ngFor Local Variables

Angular *ngFor Local Variables

In angular *ngFor exports some local variables which can be used with the current iteration:

index: Current loop iteration for each template context.
first: Boolean value indicating whether the item is the first one in the iteration.
last: Boolean value indicating whether the item is the last one in the iteration.
even: Boolean value indicating whether this item has an even index.
odd: Boolean value indicating whether this item has an odd index.

 <tr *ngFor="let d of data;let i=index;let f=first;let l=last;let e=even;let o=odd">  
        <td>{{i}}</td>  
        <td>{{d.name}}</td>
        <td>{{f}}</td>  
        <td>{{l}}</td>  
        <td>{{e}}</td>  
        <td>{{o}}</td>  
    </tr>  

Leave a Reply

Your email address will not be published. Required fields are marked *