There is such code:
$scope.$watch(NgTimeManager.getTime(), function (time) { $scope.currentTime = time; }); Where:
NgTimeManager.getTime () - returns the current time (just a number, for example: 1501589214000).
$ scope.currentTime - I want to have the current time in this variable.
Maybe I misunderstand the principle of $ watch, for reasons I do not understand, currentTime variable is not updated. What could be the problem?
UPD rewrote as the documentation does not work:
$scope.$watch(NgTimeManager.getTime(), function (newValue, oldValue) { if (newValue !== oldValue){ console.log("Changed"); $scope.currentTime = newValue; } });
$watchaccepts and see what you pass on to it - Grundywatchto a constantly changing value is a mistake, you just immediately fall into the infinit digest - Grundy$timeoutor$intervalservices, they work out at specified intervals - Grundy