如何获得单击angular2的当前索引 [英] How to get current index on click angular2
本文介绍了如何获得单击angular2的当前索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用angular2是否可以在单击时获得当前的*ngFor
索引值?
我有一个客户列表,我想获取他们的索引值.
With angular2 is it possible to get the current *ngFor
index value on click?
I have a list of clients and I want to get their index value.
<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
});
}
推荐答案
ng用于指定
index
将被设置为每个模板上下文的当前循环迭代.
index
will be set to the current loop iteration for each template context.
所以您需要这样做:
<button ion-item *ngFor="let customer of customers; let i = index;" (click)="showRadio()">
{{ i }} - {{ customer.customer_name }}
</button>
这篇关于如何获得单击angular2的当前索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文