Reputation: 20545
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
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