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 generate div and display different data from array

I’m working on an angular project and I tried to use *ngFor to generate more divs and then display data from array with ngfor index

the code from the html file (numss=5)
`

<div class="admin-container" *ngFor="let x of numss">
    <div class="heading">Allocation Key Data</div>
    <form action="#" *ngIf="newAcc">        
        <div class="card-details" >
            <div class="card-box">
   <span class="details">Provider Account ID</span>
<input type="text"  placeholder="Provider Account ID [value]="newAcc.body.unitData[x].provider_account_id">
            </div>
            <div class="card-box">
                <span class="details">Percentage</span>
                <input type="text" placeholder="Percentage" [value]="newAcc.body.unitData[x].percentage">
            </div>
</div>
</form>

`

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 :

You have to adjust your code like that:

<div class="admin-container" *ngFor="let x of newAcc">
    <div class="heading">Allocation Key Data</div>
    <div class="card-details" >
        <div class="card-box">
            <span class="details">Provider Account ID</span>
            <input type="text"  placeholder="Provider Account ID" [value]="x.provider_account_id">
        </div>
        <div class="card-box">
            <span class="details">Percentage</span>
            <input type="text" placeholder="Percentage" [value]="x.percentage">
        </div>
    </div>
</div>

ngFor works like a foreach.

You also missed a " in placeholder="Provider Account ID".

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