What is the difference between angular.copy() and an assignment (=)?

前端 未结 5 866
遇见更好的自我
遇见更好的自我 2020-12-02 17:02

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

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


        
5条回答
  •  独厮守ぢ
    2020-12-02 17:50

    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,

提交回复
热议问题