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; index as i">
3 {{item}}
4 </li>
5</ul>
1<ul>
2 <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
3 {{item}}
4 {{i}}
5 </li>
6</ul>
1You have to use let to declare the value rather than #.
2
3<ul>
4 <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
5 {{item}}
6 </li>
7</ul>
8Angular = 1
9<ul>
10 <li *ngFor="#item of items; #i = index" [attr.data-index]="i">
11 {{item}}
12 </li>
13</ul>