Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
How to get current index on click angular2

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
    });

  }

enter image description here

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

ngFor specify

index will be set to the current loop iteration for each template context.

so you need to do:

 <button ion-item *ngFor="let customer of customers; let i = index;" (click)="showRadio()">
          {{ i }} - {{ customer.customer_name }}
 </button>
about 4 years ago · Santiago Trujillo Report

0

I have figure out the solution. Just let the let i = index and set the i as a parameter inside the function.

<button ion-item *ngFor="let customer of customers; let i = index" (click)="showRadio(i)">

Credit: youtube

about 4 years ago · Santiago Trujillo Report

0

You can have the index in the customer object and then pass it in the function

[{"customer_index":1,"customer_name":"jason"},
 {"customer_index":2,"customer_name":"mary"}];

and then pass it in the function

<button ion-item *ngFor="let customer of customers" (click)="showRadio(customer.customer_index)">
            {{ customer.customer_name }}
    </button>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!