My intention is to watch a model within scope, and find difference between old value and new value.
However, I found old value and new value are all the same from th
You can use $watch
instead, that seems to work. If you want to watch all the properties on the object as well (as you are doing), you need to add true
as the third parameter to the watch. This sets up a deep watch.
Here is a working plunker.
JS:
app = angular.module('myApp',[]);
app.controller('MyCtrl', function($scope, $timeout){
$scope.markers = {};
$scope.$watch('markers', function(newValue, oldValue){
console.log('being watched oldValue:', oldValue, 'newValue:', newValue);
}, true);
$timeout( function() {
$scope.markers.foo = 1;
}, 500);
$timeout( function() {
$scope.markers.bar = 2;
}, 500);
});