user192362127 user192362127 - 6 months ago 10
AngularJS Question

How can I iterate over the keys, value in ng-repeat in angular

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

How about:

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

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