AngularJS 当调用angular-ui模式时清除$timeout

前端之家收集整理的这篇文章主要介绍了AngularJS 当调用angular-ui模式时清除$timeout前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有几个$超时表达式在模态控制器
  1. App.controller('ModalCtrl',function ($scope,$timeout) {
  2. for (var i = 0; i < 10; i++) {
  3. (function () {
  4. var timer = $timeout(function () {
  5. console.log('timer')
  6. },1000);
  7. })()
  8. }
  9. })

我需要清除所有的计时器当调用模态:

  1. App.controller('MainCtrl',$modal,$timeout) {
  2. $scope.showMap = function () {
  3. var modal = $modal.open({
  4. templateUrl: 'modalap.html',controller: 'modalCtrl',})
  5.  
  6. modal.result.then(function () { //fires when modal is resolving
  7. },function () { //fires when modal is invoking
  8. });
  9. } })

我怎样才能做到这一点?

PS对不起,代码格式错误。我不知道为什么,但我不能格式化更好。我复制代码here

$ timeout服务返回一个promise对象,可用于取消超时。
  1. // Start a timeout
  2. var promise = $timeout(function() {},1000);
  3.  
  4. // Stop the pending timeout
  5. $timeout.cancel(promise);

要取消所有挂起的超时,您需要维护promises列表,并在打开模态时取消完整列表。

猜你在找的Angularjs相关文章