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?
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With