Angular *ngfor Index 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

/* 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 */

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable