Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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(=).

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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,

over 4 years ago · Santiago Trujillo Report

0

= represents a reference whereas angular.copy() creates a new object as a deep copy.

Using = would mean that changing a property of contextwould 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.

over 4 years ago · Santiago Trujillo Report

0

When you manipulate primitive types (like int) in Javascript, = and angular.copy are the same as any assignment results in copying the value of the variable.

When you manipulate objects in Javascript, = assign a reference to the existing object to the variable and angular.copy is copying, that means creating a new object with the same properties and values and assigning the new object's reference to the variable.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!