javascript - Duplicating Angular response data so changes to one don't affect the other -
i have angular controller connected node/express server. response data request called in $http.get
can set response=$scope.x
. x
can interacted , changed. set $scope.y = $scope.x
, , changes y
result in x
changing well. however, want clone response have original response data set different variables without them changing each other.
consider response response.name = "joe"
.
$scope.x = response; $scope.y = response;
in code or view/model change x.name
such:
$scope.x.name = "bob"
however, $scope.y.name
still equal "joe"
.
i use 2 separate requests retrieve same response, i'd pass response function dynamically change data , make new version of based on for
loop. there clean, "angular" this? or simple javascript function?
angular has built in utility angular.copy()
$scope.x = response; $scope.y = angular.copy(response);
can used clean out unwanted properties angular can create such hashkeys used in ng-repeat
tracking
Comments
Post a Comment