1<ul>
2 <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
3 {{item}}
4 </li>
5</ul>
1/*
2ngFor with index in angular is used here for generating 'li' element till the studentDetails array length.
3And 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.
4*/
5
6<ul>
7 <li *ngFor="let student of studentDetails; index as i;" [attr.data-index]="i">
8 {{student}}
9 </li>
10</ul>
11
12/*
13I hope it will help you.
14Namaste
15*/
1*ngFor="let item of items; index as i;"
2// OR
3*ngFor="let item of items; let i = index;"
4// i will be the index, starting from 0
5// and you can show it in the string interpolation with {{ i }}
1<ul>
2 <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
3 {{item}}
4 {{i}}
5 </li>
6</ul>
1<ul>
2 <li *ngFor="let food of menu; index as i">
3 {{ index }},{{ food }}
4 </li>
5</ul>
6<!-- index starts from 0
7This gives an undordered list of food items in a menu, with the first item as 0-->
8