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

354
Views
How to add dynamic index from ngFor to html attribute value

I run ngFor and I need that some attribute inside the loop would change it's value by adding to it ngFor index. That's mean that each div that is created in ngFor will have uniq attribute value. Source :

<div class="class1" *ngFor="let item of items; let i= index">
    <div class="card-header" role="tab" id="Id">
        <h1>Hello</h1>
    </div>

I want to bind id to get it's value: Id0 when index=0.

<div class="card-header" role="tab" [attr.id]="Id+'i'"> Doesn't work :(
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Try:

<div class="card-header" role="tab" id="{{'Id'+i}}">
over 4 years ago · Santiago Trujillo Report

0

3 solutions

<div class="card-header" role="tab" id="{{'Id'+i}}">
<div class="card-header" role="tab" [attr.id]="'Id'+i">
<div class="card-header" role="tab" [id]="'Id'+i">
over 4 years ago · Santiago Trujillo Report

0

Your quotes seem to be wrong:

<div class="card-header" role="tab" [attr.id]="'Id'+i">

You put it around the 'i' instead of around the 'Id'

over 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!