jawahar
jawahar

Reputation: 85

Property 'indx' does not exist on type

I have been working on Angular 5 project and I was trying run npm build -prod with AOT as defult one. After compiling error pop up as

Property 'indx' does not exist on type 'EntryComponent'

Can any on point out the mistake. Or it some thing else.

<div *ngFor="let form of getEntryGroupItemsControl(); let indx = index; trackBy: indx">

Upvotes: 3

Views: 3096

Answers (2)

I had the same problem. I fixed it using "index as i".

https://angular.io/api/common/NgForOf

Upvotes: 1

Mateusz Witkowski
Mateusz Witkowski

Reputation: 1746

The reason is the wrong syntax. trackBy should point to a function, not to an index from the loop. So it should by something like this:

<div *ngFor="let form of getEntryGroupItemsControl(); let indx = index; trackBy: trackByFn">

And in TS file for example:

trackByFn(index, item) { 
  return item.id; 
}

For reference see: 1) https://angular.io/api/common/NgForOf 2) https://angular.io/api/core/TrackByFunction

And here`s an example from official Angular tutorial: https://angular.io/guide/template-syntax#ngfor-with-trackby

Upvotes: 3

Related Questions