Angular 属性 绑定 ngForTrack 未被任何指令使用

Angular Property binding ngForTrack not used by any directive

我正在努力将 angular 1.x 站点转换为 angular 2.6,我正在尝试获取一些文本和 URL 来显示,我从旧站点获得以下代码:

<div ng-repeat="item in cartCtrl.downloadFinishedItems track by $index">
    <div class="links-14">
        <a ng-show="item.downloadJob.downloadLink"
              ng-click="cartCtrl.downloadFile(item)">{{item.name}}</a>
    </div>
</div>

但是当我转换为:

<div *ngFor="let item of downloadFinishedItems track by $index">
    <div class="links-14">
        <a [hidden]="!item.downloadJob.downloadLink"
            (click)="downloadFile(item)">{{item.name}}</a>
    </div>
</div>

我收到以下错误:

新的相当于那条线吗? :

 <div *ngFor="let item of downloadFinishedItems; index as i; trackBy:i">

the NgForOf documentation所述:

To customize the default tracking algorithm, NgForOf supports trackBy option. trackBy takes a function which has two arguments: index and item. If trackBy is given, Angular tracks changes by the return value of the function.

在你的情况下,它将是:

<div *ngFor="let item of downloadFinishedItems; trackBy: trackByIndex">

使用方法:

trackByIndex(index, item) {
  return index;
}