0
    <table class="table table-striped">
  <thead>
    <tr>
      <th>#</th>
      <th ng-repeat="header in headers">{{header}}</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="table in tables">
      <td>{{$index+1}}</td>
      <td ng-repeat="header in headers">{{$parent.table.header}}</td>
    </tr>
  </tbody>
</table>

I have a json array retrieved from a server. First ng-repeat: 'headers' contain keys in that json array which i extracted. It works fine in all cases. Second ng-repeat: 'tables' contain the json array received. What i am trying to do is for each element of json array, find data by providing key values. here is my multiple ng-repeat code. This doesn't work, no data is printed in the table but if i change {{$parent.table.header}} to {{$parent.table}} or {{header}} i can see data in the table. The problem is {{$parent.table.header}} how can i do it correctly ?

Jithin Sebastian
  • 511
  • 1
  • 6
  • 19
  • it isn't clear what you are trying to output here. Can you provide more information, specifically what your data looks like, and what you expect to see in the output? – Claies Sep 29 '16 at 06:22
  • post your code in plunkr will be use full to resolve your problem – balajivaishnav Sep 29 '16 at 06:27

1 Answers1

1

Try to use $parent.table[header] - because header is already a string.

  • that worked...but table is not an array, it is a json string. so i can access json like this ? i thought i can access it only by 'dot' – Jithin Sebastian Sep 29 '16 at 06:36
  • Well keys are properties - but when looping over object's keys they defined as strings - then you can access them with ["STRING GOES HERE"]; http://stackoverflow.com/questions/3608246/what-is-the-type-of-keys-in-javascript – Yoav Shmaria Sep 29 '16 at 06:45