Marc Rasmussen
Marc Rasmussen

Reputation: 20545

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?

Upvotes: 0

Views: 42

Answers (2)

KrishCdbry
KrishCdbry

Reputation: 1059

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

Upvotes: 1

Юра Панарин
Юра Панарин

Reputation: 849

You can use $scope.$watch

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

Upvotes: 0

Related Questions