首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在单击angular2时获取当前索引

如何在单击angular2时获取当前索引
EN

Stack Overflow用户
提问于 2017-04-18 04:49:03
回答 3查看 21K关注 0票数 6

使用angular2可以在点击时获得当前的*ngFor索引值吗?我有一个客户列表,我想要获取它们的索引值。

代码语言:javascript
运行
复制
<button ion-item *ngFor="let customer of customers" (click)="showRadio()">
    {{ customer.customer_name }}
</button>
代码语言:javascript
运行
复制
  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
    });

  }

EN

Stack Overflow用户

发布于 2017-04-18 05:00:20

您可以将索引放在customer对象中,然后将其传递给函数

代码语言:javascript
运行
复制
[{"customer_index":1,"customer_name":"jason"},
 {"customer_index":2,"customer_name":"mary"}];

然后在函数中传递它

代码语言:javascript
运行
复制
<button ion-item *ngFor="let customer of customers" (click)="showRadio(customer.customer_index)">
            {{ customer.customer_name }}
    </button>
票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43459344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档