mkteagle
mkteagle

Reputation: 579

Angular 2: *ngfor not letting me declare an index

I am trying to declare an index in *ngFor but I am getting a type error and it is saying

Cannot read property 'toUpperCase' of undefined with the ERROR on *ngFor

<div class="text" *ngFor="let item of blogs; let i = index | async | filter : 'feat' : true">

If I take out let i = index it works fine, but I want to use the index, so I can apply css classes to the elements. Looking at documentation, this is how you are supposed to do it.

Upvotes: 0

Views: 763

Answers (2)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657308

index is maintained by ngFor and exported as index. All you can do is to define a name of a template variable you want to access that index with. You can't apply pipes or calculations to that assignment.

Upvotes: 1

Philippe Plantier
Philippe Plantier

Reputation: 8073

It should be

<div class="text" *ngFor="let item of blogs | async | filter : 'feat' : true; let i = index">

Upvotes: 1

Related Questions