Marc Rasmussen Marc Rasmussen - 2 months ago 7
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
this.newAbsenceType
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

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 : https://jsbin.com/jucebix/9/edit?html,js,console