Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
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

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

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>
over 4 years ago · Santiago Trujillo Relatório

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

over 4 years ago · Santiago Trujillo Relatório

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>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda