Jithin Sebastian Jithin Sebastian - 2 months ago 19
AngularJS Question

Using multiple ng-repeat

<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 ?

Answer

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