如何获取单击angular2的当前索引
发布时间:2020-12-17 17:05:01 所属栏目:安全 来源:网络整理
导读:使用angular2可以在点击时获得当前的* ngFor索引值吗? 我有一个客户列表,我想获得他们的索引值. button ion-item *ngFor="let customer of customers" (click)="showRadio()" {{ customer.customer_name }}/button showRadio(currentIndex) { //...........
使用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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |