Answers for "index ngfor"

7

ngfor index

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>
Posted by: Guest on February-26-2020
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
*/
Posted by: Guest on May-07-2020
1

how to get index for ngfor

*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 }}
Posted by: Guest on August-02-2020
1

ngfor index

<ul>
    <li *ngFor="let item of items; index as i">
        {{item}}
    </li>
</ul>
Posted by: Guest on July-02-2020
0

ngfor index

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
        {{i}}
    </li>
</ul>
Posted by: Guest on August-24-2020
0

index in ng for

You have to use let to declare the value rather than #.

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>
Angular = 1
<ul>
    <li *ngFor="#item of items; #i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>
Posted by: Guest on June-20-2021

Browse Popular Code Answers by Language