Con angular2, ¿es posible obtener el valor actual del índice *ngFor al hacer clic? Tengo una lista de clientes y quiero obtener su valor de índice.
<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 }); }ngPara especificar
index se establecerá en la iteración de bucle actual para cada contexto de plantilla.
así que tienes que hacer:
<button ion-item *ngFor="let customer of customers; let i = index;" (click)="showRadio()"> {{ i }} - {{ customer.customer_name }} </button>Puede tener el índice en el objeto del cliente y luego pasarlo en la función
[{"customer_index":1,"customer_name":"jason"}, {"customer_index":2,"customer_name":"mary"}];y luego pasarlo en la función
<button ion-item *ngFor="let customer of customers" (click)="showRadio(customer.customer_index)"> {{ customer.customer_name }} </button>