簡體   English   中英

類型不存在屬性“ 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

我有同樣的問題。 我使用“我的索引”修復了它。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM