Angular Watch Working.
by Mayank Dixit
HTML
<div ng-controller="mainCtrl">
<button ng-click="change()">Change</button>
</div>
JavaScript
angular.module("myApp", [])
.controller("mainCtrl", function($scope){
setInterval(function(){
$scope.sample = new Date();
$scope.$apply();
}, 2000);
$scope.$watch("sample", function(x, y){
console.log($scope.sample, x, y);
});
$scope.change = function(){
$scope.sample = new Date();
}
});