AngularJS。调用角UI模式时,清除$超时 [英] AngularJS. Clear $timeout when invoking angular-ui modal
本文介绍了AngularJS。调用角UI模式时,清除$超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个 $超时
在模态控制器前pressions
I have several $timeout
expressions in Modal controller
App.controller('ModalCtrl', function ($scope, $timeout) {
for (var i = 0; i < 10; i++) {
(function () {
var timer = $timeout(function () {
console.log('timer')
}, 1000);
})()
}
})
我需要清除所有定时器调用模式时:
I need to clear all the timers when invoking the modal:
App.controller('MainCtrl', function ($scope, $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
});
} })
我怎样才能做到这一点?
How can I do that?
PS抱歉坏code格式。我不知道为什么,但我不能更好的格式化。我复制code 这里:
PS Sorry for bad code formatting. I don't know why but I cant format it better. I duplicated code here:
推荐答案
在$超时服务返回,可用于取消超时的承诺对象。
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.
这篇关于AngularJS。调用角UI模式时,清除$超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文