AngularJS. Clear $timeout when invoking angular-ui modal

后端 未结 2 667
北恋
北恋 2020-12-28 11:48

I have several $timeout expressions in Modal controller

App.controller(\'ModalCtrl\', function ($scope, $timeout) {
    for (var i = 0; i < 1         


        
相关标签:
2条回答
  • 2020-12-28 12:16

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

    (function(){
      var timer = $timeout(function(){
        console.log(timer.$$timeoutId);
        $timeout.cancel(timer);
      }, 1000);
    })();
    
    0 讨论(0)
  • 2020-12-28 12:24

    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
    $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.

    0 讨论(0)
提交回复
热议问题