How to iterate over the keys and values with ng-repeat in AngularJS?

user192362127 picture user192362127 · Feb 28, 2013 · Viewed 551.4k times · Source

In my controller, I have data like: $scope.object = data

Now this data is the dictionary with keys and values from json.

I can access the attribute with object.name in the template. Is there any way that I can iterate over the keys as well and display them in table like

<tr><td> {{key}} </td> <td> data.key </td>

The data is like this

{
    "id": 2,
    "project": "wewe2012",
    "date": "2013-02-26",
    "description": "ewew",
    "eet_no": "ewew",
}

Answer

Josh David Miller picture Josh David Miller · Feb 28, 2013

How about:

<table>
  <tr ng-repeat="(key, value) in data">
    <td> {{key}} </td> <td> {{ value }} </td>
  </tr>
</table>

This method is listed in the docs: https://docs.angularjs.org/api/ng/directive/ngRepeat