Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

422
Vistas
How can I access the index outside *ngFor?

I want to use the variable i outside of my ngFor. What options are there to solve this problem?

Here is a small application example:

<ng-container *ngFor="let selection of selectionNumber; index as i;">
        <app-MyDropdown
          tabindex="{{i}}"
        ></app-MyDropdown
></ng-container>
<div>
    <button
      type="button"
      tabindex="{{i+1}}"
    >
      Button 1
    </button>
    <button
      type="button"
      color="primary"
      tabindex="i+2"
    >
      Button 2
    </button>
</div>

I want to use the i variable outside of the for loop to set the tab index. For this i should have the last value from the loop iteration.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It's not possible to use any value of *ngFor outside of whichever element you're running your ngFor loop in, (in your case that is ng-container). Which means you have to put your buttons inside of your ngContainer which will create button. But not sure if that's what you want to achieve.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can not access any data of *ngFor from outside of the loop

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda