0

I'm trying to display an object of an object in an array, I've been hitting my head against the wall since I cant change the backend. this is what I got so far, M01, M02, M03... might refer to months since we are November there are 11 however if it was February id be only M01 and M02. since I got a property of an object I cant loop it on a second for and I'm having a lot of trouble with it

Array to display

this is my view

<div *ngIf="estados" class="table-responsive col-lg-12 tablilla">
  <table class="table table-bordered table-striped table-responsive">
    <thead>
    <tr>
      <th></th>
      <th *ngFor="let month of listaMonthsNames">{{month}}</th>
    </tr>
    </thead>
    <tbody>
    <tr *ngFor="let estado of estados">
      <td>{{estado.nom_item}}</td>
      <td *ngFor="let month of estado.M[0]">{{month}}</td>
    </tr>
    </tbody>
  </table>
</div>

1 Answer 1

1

I think this will help you :

There is no direct way to access Object from the Template side so,

All you need to do is provide Object.keys access to the Template side by this way from Component :

// Component Side :
objectKeys = Object.keys;

// Template Side :
<td *ngFor="let key of objectKeys(estado.M)">
    Key: {{key}}, value: {{estado.M[key]}}
</td>

You can read more about the Object.keys HERE

Sign up to request clarification or add additional context in comments.

2 Comments

@RildoGomez, please go through the link once, you will get the idea.
Thank you Vivek Doshi! it needed a little change tho, it was only *ngFor="let key of objectKeys(estado.M)">{{estado.M[key]}} without [0]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.