I want to be able to have multiple input fields be able to change an object that is returned from an ajax call. I'm not sure how I can prevent the linking of the two objects.
$scope.items = [{value: 1},{value: 2},{value: 3}];
$scope.itemEdit1 = $scope.items;
$scope.itemEdit2 = $scope.items;
Do I have to each edit in a different scope? Here is a fiddle describing my problem: /
I want to be able to have multiple input fields be able to change an object that is returned from an ajax call. I'm not sure how I can prevent the linking of the two objects.
$scope.items = [{value: 1},{value: 2},{value: 3}];
$scope.itemEdit1 = $scope.items;
$scope.itemEdit2 = $scope.items;
Do I have to each edit in a different scope? Here is a fiddle describing my problem: http://jsfiddle/htTQc/
Share Improve this question asked Oct 22, 2012 at 15:45 rcellrcell 6711 gold badge10 silver badges17 bronze badges1 Answer
Reset to default 14Seems like maybe you want to copy the objects, so you're not editing the same reference? Just use angular.copy
. Docs here.
$scope.items = [{value: 1},{value: 2},{value: 3}];
$scope.itemEdit1 = angular.copy($scope.items);
$scope.itemEdit2 = angular.copy($scope.items);
http://jsfiddle/blesh/htTQc/1/