I wanna update an object within an objects array. Is there another possibility than iterating over all items and update the one which is matching? Current code looks like the following:
angular.module('app').controller('MyController', function($scope) { $scope.object = { name: 'test', objects: [ {id: 1, name: 'test1'}, {id: 2, name: 'test2'} ] }; $scope.update = function(id, data) { var objects = $scope.object.objects; for (var i = 0; i < objects.length; i++) { if (objects[i].id === id) { objects[i] = data; break; } } } });
update()
, pass in the object instead of the id.ng-click="update(obj, data)"
instead ofng-click="update(obj.id, data)"