I want to edit an array of objects, which are tied to the view by an ng-repeat
.
How can I avoid updating the scope until the complete array has been modified?
Here is a simple example:
I would like to update every obj in array and ONLY then update the $scope. Since the array contains objects I cannot simply copy them over in another variable.
<div ng-click="updateAll()" ng-repeat="obj in array">obj.value</div>
angular.module("test", []).controller('Ctrl', function($scope) {
$scope.array = [{val: 1}, {val: 2}, {val: 3});
$scope.updateAll = function() {
for (var i = $scope.array.length - 1; i >= 0; i--) {
$scope.array[i].val2 = i;
};
};
});