简体   繁体   English

类型不存在属性“ indx”

[英]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. 我一直在从事Angular 5项目,并尝试将npm build -prod与AOT结合使用。 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. trackBy应该指向一个函数,而不是循环中的索引。 So it should by something like this: 所以它应该是这样的:

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

And in TS file for example: 并以TS文件为例:

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

For reference see: 1) https://angular.io/api/common/NgForOf 2) https://angular.io/api/core/TrackByFunction 作为参考,请参见: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 这是来自官方Angular教程的示例: 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 https://angular.io/api/common/NgForOf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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