ngFor with index as value in attribute

Forums AngularngFor with index as value in attribute
Staff asked 1 month ago

I want to store index value in attribute what I do for that?

Answers (1)

Add Answer
Staff answered 1 month ago

you can store value of index in ngFor  as an attribute by using this syntax.

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

Here value of index i is store in data-index attribute.

Subscribe

Select Categories