Reputation: 11614
I have a json object(items) and I am iterating through ngFor. I need to assign index value to variable i only if it matches the condition item.isRepetable==true
Is there any way I can assign the index value to variable i in *ngFor on condition matches
<ul *ngFor="let item of items;let i=item.isRepetable?index:0">
<li>{{item}}</li>
</ul>
Upvotes: 0
Views: 903
Reputation: 657691
Create and apply a filter pipe, then you don't need a condition and the index will match.
<ul *ngFor="let item of items | isRepeatableFilter;let i=index">
<li>{{item}}</li>
</ul>
There is no way to modify the index generated by *ngFor
Upvotes: 1