user3162402 user3162402 - 1 year ago 140
AngularJS Question

AngularJS. Clear $timeout when invoking angular-ui modal

I have several

expressions in Modal controller

App.controller('ModalCtrl', function ($scope, $timeout) {
for (var i = 0; i < 10; i++) {
(function () {
var timer = $timeout(function () {
}, 1000);

I need to clear all the timers when invoking the modal:

App.controller('MainCtrl', function ($scope, $modal, $timeout) {
$scope.showMap = function () {
var modal = ${
templateUrl: 'modalap.html',
controller: 'modalCtrl',

modal.result.then(function () { //fires when modal is resolving
}, function () { //fires when modal is invoking
} })

How can I do that?

PS Sorry for bad code formatting. I don't know why but I cant format it better. I duplicated code here:

Answer Source

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

// Start a timeout
var promise = $timeout(function() {}, 1000);

// Stop the pending timeout

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download