The normal way of learning ng-repeat is as follows
<li ng-repeat="item in items">{{item.attribute}}</li>
and you would have a controller such as
app.controller('myCtrl', function($scope) {
$scope.items = [
{ name : kitten, attribute : value },
{ name : puppy, attribute : value }
];
});
This is good and all, but it gets clunky when I get deeper into my app and have to reference items by their array index. A function that modify's kitten's attribute will go:
$scope.items[0].attribute = value;
I would much rather have:
app.controller('myCtrl', function($scope) {
$scope.items = {
'kitten' : {attribute : value },
'puppy' : { attribute : value }
};
});
so that I can
$scope.items.kitten.attribute = NEW
-or-
$scope.items["kitten"].attribute = NEW
(are these equivalent?? I think so)
But then how would I loop through them?
<li ng-repeat="item in items">{{item.attribute}}</li>
does not work.