使用angular2可以在点击时获得当前的*ngFor索引值吗?我有一个客户列表,我想要获取它们的索引值。
<button ion-item *ngFor="let customer of customers" (click)="showRadio()">
    {{ customer.customer_name }}
</button>  showRadio(currentIndex) {
  //................    
  for(var j=0; j<myResult[currentIndex].bookingIds.length; j++) {
    alert.addInput({
      type: 'radio',
      label: myResult[currentIndex].bookingIds[j],
      value: myResult[currentIndex].bookingIds[j],
      checked: false
    });
  }

发布于 2017-04-18 05:00:20
您可以将索引放在customer对象中,然后将其传递给函数
[{"customer_index":1,"customer_name":"jason"},
 {"customer_index":2,"customer_name":"mary"}];然后在函数中传递它
<button ion-item *ngFor="let customer of customers" (click)="showRadio(customer.customer_index)">
            {{ customer.customer_name }}
    </button>https://stackoverflow.com/questions/43459344
复制相似问题