문제

여러가지 $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', 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
        });
    } })

렇게 하려면 어떻게 해야 합니까?

PS 죄송에 대한 잘못된 코드 서식을 지정합니다.이유는 모르겠지만 나는 형식입니다.내가 중복되는 코드 :

도움이 되었습니까?

해결책

$timeout 서비스 반환 Promise 체할 수 있는 사용을 취소한다.

// Start a timeout
var promise = $timeout(function() {}, 1000);

// Stop the pending timeout
$timeout.cancel(promise);

을 취소하 보류 중인 모든 시간 제한,당신은 당신을 유지하기 위해 필요 목록의 약속 취소가 완전한 목록을 열면 모달입니다.

다른 팁

수도 있습니다 그들이 취소 자신을 이렇게 하여...

(function(){
  var timer = $timeout(function(){
    console.log(timer.$$timeoutId);
    $timeout.cancel(timer);
  }, 1000);
})();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top