使用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 }); }
解决方法
ngFor指定
index将设置为每个模板上下文的当前循环迭代.
所以你需要这样做:
<button ion-item *ngFor="let customer of customers; let i = index;" (click)="showRadio()"> {{ i }} - {{ customer.customer_name }} </button>