I am facing an issue with my function $scope.render()
that relies on the value of $scope.myProperty
to render a chart. Whenever myProperty
changes during a digest cycle, I need to ensure that $scope.render()
is called only once at the end of the digest cycle.
$scope.$watch('myProperty', function(v, vold) {
if ($scope.switch) {
$scope.myProperty ++;
$scope.switch = false;
}
$scope.render();
});
The problem here is that if $scope.switch
is true, then $scope.render()
will be invoked twice within the same digest cycle. How can I make sure it's called only once?