mercredi 26 août 2015

ng-repeat for an json object which has arrays

I have a JSON object which is data for a chart. This has 2 properties labels and data. Both are arrays. Along with the chart I wish to display a table as well. I am not able to figure out how to use the ng-repeat directive here.

JSON Object

$scope.chartdata={
          labels: ["XYZ", "ABC","DEF"],
          data: [4286, 38870, 3955]
  };

HTML

<table class="table table-striped">
        <thead>
            <tr>
            <th>Labels</th>
            <th>Data </th>
            </tr>
        </thead>
        <tr ng-repeat="cht in chartdata">
            <td>{{cht.labels}}</td>
            <td>{{cht.data}}</td>
        </tr>           
    </table>

Do I need to change the JSON structure? I do not wish to cos it works for my chart directive and I want to resues the same JSON for displaying the table as well.




Aucun commentaire:

Enregistrer un commentaire