ngfor index angular code example
Example 1: ngfor index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
</li>
</ul>
Example 2: ngfor get index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
</li>
</ul>
Example 3: ngfor index
<ul>
<li *ngFor="let student of studentDetails; index as i;" [attr.data-index]="i">
{{student}}
</li>
</ul>
Example 4: how to get index for ngfor
*ngFor="let item of items; index as i;"
*ngFor="let item of items; let i = index;"