ngfor在元素click事件中使用索引

时间:2018-10-03 01:35:12

标签: angular angular6

我试图在芯片上设置一个删除按钮,所以我尝试了:

<mat-chip-list>
  <mat-chip *ngFor="let condition of conditions; let i = index">
    {{condition.column.friendlyName}} {{condition.operator.symbol}} {{condition.value}} 
    <mat-icon class="close-icon" (click)="removeChip(i)">highlight_off</mat-icon>
  </mat-chip>
</mat-chip-list>

但是它表示i未定义。单击该索引可获得筹码索引的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

此内容以5度以上的角度更新为index as i

<mat-chip *ngFor="let condition of conditions; index as i"> 
  {{condition.column.friendlyName}} {{condition.operator.symbol}} {{condition.value}} 
  <mat-icon class="close-icon" (click)="removeChip(i)">highlight_off</mat-icon>
</mat-chip>