I have the following $scope.$watch
in the controller of a directive that I created:
var interval;
$scope.$watch('active', function () {
if ($scope.active == true) {
interval = $interval(function () {
if ($scope.current >= $scope.to) {
// Quero destruir o Watch aqui.
return $interval.cancel(interval);
}
$scope.current += amounth;
}, 10);
}
});
When the value falls within the condition indicated above by a comment, I would like $watch
to be turned off / destroyed, since I will no longer need to detect changes in the active
value.
Is there any way to destroy / disable an Angular watch?