AngularJS. Clear $timeout when invoking angular-ui modal AngularJS. Clear $timeout when invoking angular-ui modal javascript javascript

AngularJS. Clear $timeout when invoking angular-ui modal


The $timeout service returns a Promise object which can be used to cancel the timeout.

// Start a timeoutvar promise = $timeout(function() {}, 1000);// Stop the pending timeout$timeout.cancel(promise);

To cancel all pending timeouts, you need to maintain a list of promises and cancel the complete list when you open the modal.


You may also let them cancel themselves by doing this...

(function(){  var timer = $timeout(function(){    console.log(timer.$$timeoutId);    $timeout.cancel(timer);  }, 1000);})();