0

I am getting the following json from a database, and I want to do an ngfor;but I don't know how to do it with this kind of JSON

link codebeautify.org

<div class="col-md-4" *ngFor="let referencia of referencias.rows">
       <div class="card text-center">
           <div class="card-header">

           </div>
           <div class="card-body">
               {{referencia.2}}
           </div>
      </div>
   </div>
1
  • As per your JSON, you'll require a nested *ngFor. Commented Jul 25, 2019 at 4:17

2 Answers 2

1

You need to parse your json return from the API first before using it:

In the ts file where you receive your data:

referencias = JSON.parse(referencias);

And since each referencia from referencias.rows is an Array, you access it data like this referencia[arrayIndex]:

<div class="col-md-4" *ngFor="let referencia of referencias.rows">
    <div class="card text-center">
        <div class="card-header">
        </div>
        // Changed referencia.2 to referencia[2]
        <div class="card-body">
               {{referencia[2]}} // Should show 'AYALA'
        </div>
    </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

In your ts file, I am assuming referencias is the parsed json response of the API. The below solution is to get all the rows.

<div class="col-md-4" *ngFor="let referencia of referencias['rows']">
   <div class="card text-center">
       <div class="card-header">

       </div>
       <div class="card-body" *ngFor="let rowData of referencia">
           {{rowData}}
       </div>
  </div>

Hope this works for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.