Friday, December 25, 2015

AngularJS Cancel $timeout

$timeout returns a promise. This promise is resolved when delay is passed and the timeout function is executed.

To cancel the timeout request, call $timeout.cancel(promise).

Here is an example on how to cancel the $timeout

//setting timeout and storing the return value in a local variable
var promise = $timeout(function () {
    //code to be executed after 50 milliseconds
}, 50);

//Cancelling the above timeout by passing the promise