简体   繁体   中英

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">

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM