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

【字号: 日期:2024-04-11浏览:34作者:雯心
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解决AngularJS调用angular-ui模态时清除$ timeout?

该$timeout服务返回一个Promise可用于取消超时的对象。

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

要取消所有未决超时,您需要维护一个诺言列表,并在打开模式时取消整个列表。

解决方法

我$timeout在Modal控制器中有几个表达式

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

调用模式时,我需要清除所有计时器:

App.controller(’MainCtrl’,$modal,$timeout) { $scope.showMap = function () {var modal = $modal.open({ templateUrl: ’modalap.html’,controller: ’modalCtrl’,})modal.result.then(function () { //fires when modal is resolving},function () { //fires when modal is invoking}); } })

我怎样才能做到这一点?

PS对不起,错误的代码格式。我不知道为什么,但我无法更好地格式化它。我在这里重复了代码:

相关文章: