What is the difference between angular.copy() and an assignment (=)?
=
represents a reference whereas angular.copy()
creates a new object as a deep copy.
Using =
would mean that changing a property of context
would change the corresponding property of $scope.master
or vice versa.
Using angular.copy()
the two objects would remain seperate and changes would not reflect on each other.
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,