angular ngfor index
snippet in html

ngfor get index

user8760

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>

angular ngfor index

user3021

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>

ngfor index

user6877

/*
ngFor with index in angular is used here for generating 'li' element till the studentDetails array length.
And also make a note if you are using angular 1 then you have to replace 'let' with '#', but its ok if you are using angular 2 or above.
*/

<ul>
    <li *ngFor="let student of studentDetails; index as i;" [attr.data-index]="i">
        {{student}}
    </li>
</ul>

/*
I hope it will help you.
Namaste
*/

how to get index for ngfor

user9261

*ngFor="let item of items; index as i;" 
// OR
*ngFor="let item of items; let i = index;"
// i will be the index, starting from 0 
// and you can show it in the string interpolation with {{ i }}

ngfor index

user3952

<ul>
    <li *ngFor="let item of items; index as i">
        {{item}}
    </li>
</ul>