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

412
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Juan Pablo Isaza 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!