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.net/htTQc/
Seems 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);