Reputation: 3739
I use $timeout
to routinely update the info on one of the page in my angularjs app. I'd like to cancel the $timeout
when user navigate away from this page. Is there a simple way to do that?
Upvotes: 7
Views: 3305
Reputation: 3739
Ok, I found the solution after digging around:
$scope.$on('$destroy', function() {
$timeout.cancel(timeout);
});
Or for the new component syntax in Angular 1.5:
this.$onDestroy = function() {
if (timeout) {
$timeout.cancel(timeout);
}
}
Upvotes: 13