How to update the entire dictionary if any item has been changed?
<body ng-controller="SomeListCtrl">
<ul>
<li ng-repeat="user in users">
{{bindUserToImg(user.id)}}
</li>
</ul>
<button ng-click="update()">Update img</button>
</body>
function SomeListCtrl($scope) {
$scope.users = [
{id: 1},
{id: 2},
{id: 3}
];
$scope.images = {
1: {src: 'img-1'},
2: {src: 'img-2'},
3: {src: 'img-3'}
};
$scope.bindUserToImg = function(x) {
console.log(x);
return $scope.images[x].src;
};
$scope.update = function() {
$scope.images[2].src = 'updated-img';
};
}
Code: http://jsbin.com/sanipiki/1/
I linked users to images. Now, if some image changes (call the "update" method to change image # 2), angular will update all users (the "bindUserToImg" method will be called for each element in the "users" array). Is it possible to make angular to update only a specific image and prevent the updating of all dictionary elements?
+4