Marc Rasmussen Marc Rasmussen - 1 year ago 46
AngularJS Question

Angularjs applying update to object

So say you have the following code:

var absenceType = {name: 'hello'};
this.newAbsenceType = angular.copy(absenceType);

Now you make changes to
and you wish to apply these changes to the original object.

So ive been looking at extend:

angular.extend( absenceType, this.newAbsenceType);

However this did not do the trick.

What am i doing wrong?

Answer Source

Use merge

 angular.merge(absenceType, this.newAbsenceType);

But extend also should work the same way the only difference between them is merge deeply extends the destination object.

Demo :,js,console