Docs: https://code.angularjs.org/1.2.26/docs/api/ng/directive/ngRepeat
The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and $index is set to the item index or key.
It seems like I'm getting the index not the key.
Controller:
$scope.items = {
"key1" : "val1",
"key2" : "val2"
};
View:
<div class="item" ng-repeat="item in items">{{ $index }} {{item}}</div>
Result:
0 val1
1 val2
http://plnkr.co/edit/0g9EL6kqYcm4jNpdDZ9L?p=preview
I'd like to display key, which in this case should be key1
and key2
. Is there a special syntax for that?