0

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?

2
  • angular.copy returns "The copy or updated destination, if destination was specified." Commented Sep 23, 2016 at 10:52
  • angular.extend( absenceType, this.newAbsenceType) should work. If it doesn't then you are doing something wrong which you don't show in the question. Commented Sep 23, 2016 at 10:58

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

is merge a function from angular 1.4 and above?
0

You can use $scope.$watch

$scope.$watch(function(){ return this.newAbsenceType}, function(newValue, oldValue) {
  //do change
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.