For more information, check out the documentation: https://code.angularjs.org/1.2.26/docs/api/ng/directive/ngRepeat
The ngRepeat directive creates a template for each item in a collection. Each template has its own scope with the current item assigned to the loop variable, and $index representing the index or key of the item.
It appears I am accessing the index instead of the key.
Controller:
$scope.items = {
"key1" : "val1",
"key2" : "val2"
};
View:
<div class="item" ng-repeat="(key, value) in items">{{ key }} {{value}}</div>
Result:
key1 val1
key2 val2
http://plnkr.co/edit/0g9EL6kqYcm4jNpdDZ9L?p=preview
I want to display the key, which should be key1
and key2
in this case. Is there a special syntax for that?