属性 'indx' 类型不存在

Property 'indx' does not exist on type

我一直在从事 Angular 5 项目,我尝试 运行 npm build -prod 将 AOT 作为默认项目。编译后报错为

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

哪位能指出错误。或者是别的东西。

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

原因是语法错误。 trackBy 应该指向一个函数,而不是循环中的索引。所以它应该是这样的:

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

以TS文件为例:

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

参考: 1) https://angular.io/api/common/NgForOf 2) https://angular.io/api/core/TrackByFunction

这是来自官方 Angular 教程的示例:https://angular.io/guide/template-syntax#ngfor-with-trackby

我遇到了同样的问题。我使用 "index as i".

修复了它

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