Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make the index from ngFor part of an html tag value

I have an ngFor loop set up like this:

<div *ngFor="let record of this.RecordsProcessed; let i = index">
   <div class="row my-16" data-test='test'_{{i}}>
        <div class="col-4">Id:</div>
        <div class="col-8">{{record?.Id}}</div>
    </div>
</div>

I want to put the index from ngFor on the data-text tag within the html. Is it possible to do something like this within the html?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try like this:

  <div *ngFor="let record of this.RecordsProcessed; let i = index">
  <div class="row my-16" [attr.data-test]="'test_' + i">
       <div class="col-4">Id:</div>
       <div class="col-8">{{record?.Id}}</div>
   </div>
</div>

[] brackets let angular know that everything inside of "" is typescript code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading