0

I need to display a table using Angular ng-repeat but I don't know it's keys in advance.

Like, the response of API is Array of Objects

And, each Object has unknown keys.

enter image description here

In my HTML, I am doing ng-repeat over responseData.data.rows

<table id="customers">
  <tr ng-repeat = "x in myCtrl.demoDetails">

  </tr>
</table>

But how would I print values in table?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
StrugglingCoder
  • 4,611
  • 12
  • 60
  • 98
  • Please have a look here [Object.keys](https://stackoverflow.com/questions/25299436/unable-to-call-object-keys-in-angularjs). You can make use of `Object.keys` but that has limitations with `angularjs`. Check the answer for better understanding – Shaheryar.Akram Dec 12 '18 at 10:44

1 Answers1

2

It should look something like below,

<table class="table">
  <tr>
    <td>Task Name</td>
    <td>End Date</td>
    <td>Service Key</td>
  </tr>
<tr ng-repeat="x in responseData.data.rows">
  <td>{{x.task_name}}</td>
  <td>{{x.end_date}}</td>
  <td>{{x.service_key}}</td> 
</tr>
</table>
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376