using index in ngFor 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 index
<ul>
<li *ngFor="let student of studentDetails; index as i;" [attr.data-index]="i">
{{student}}
</li>
</ul>
Example 3: how to get index for ngfor
*ngFor="let item of items; index as i;"
*ngFor="let item of items; let i = index;"
Example 4: ngfor index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
{{i}}
</li>
</ul>