我有几个$超时表达式在模态控制器
- 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
- });
- } })
我怎样才能做到这一点?
$ timeout服务返回一个promise对象,可用于取消超时。
- // Start a timeout
- var promise = $timeout(function() {},1000);
- // Stop the pending timeout
- $timeout.cancel(promise);
要取消所有挂起的超时,您需要维护promises列表,并在打开模态时取消完整列表。