How can I define the index
variable in @for
in Angular 17
const users = [
{ id: 1, name: 'Ali' },
{ id: 2, name: 'reza' },
{ id: 3, name: 'jack' },
];
<ul>
@for (user of users; track user.id; let i = index) {
<li>{{ user.name + i }}</li>
} @empty {
<span>Empty list of users</span>
}
</ul>
index is not known as we had in *ngFor
and got Unknown "let" parameter variable "index" in Angular17 @for
But the following is working:
<ul>
<li *ngFor="let user of users; let i = index">{{ user.name + i }}</li>
</ul>