Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  60] [ 2]  / answers: 1 / hits: 43795  / 9 Years ago, mon, april 20, 2015, 12:00:00

I want to assign some values when a button click event happens via event parameter:



$scope.update = function(context) {
$scope.master = context;
};


I have assigned user values to $scope.master.



Now i am seeing angular.copy(). So I wrote the code with angular.copy.



$scope.update = function(context) {
$scope.master = angular.copy(context)
};


Both are doing same, so what is the difference? Please tell me about the difference between angular.copy() and equal(=).


More From » angularjs

 Answers
2

As can be read here angular.copy() performs a deep copy (cf. clone) of the argument - essentially creating a new object - whereas using the assignment operator = just assigns reference's.



Thus in the latter case, if you we're to change something in $scope.master you would also change context.



Cheers,


[#66992] Saturday, April 18, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kennedi

Total Points: 702
Total Questions: 109
Total Answers: 111

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
;