我想在angularjs中为我的倒数计时器添加暂停按钮

时间:2015-06-17 16:05:55

标签: javascript angularjs timer

$scope.countdown = function () {
    countdownStop = $timeout(function () {
        if ($scope.counter == 0) {
            $scope.stop();
            $scope.completeRound();

        }
        else {
            $scope.counter--;
            $scope.countdown();
        }
    }, 1000);
};

$scope.stop = function () {
    $timeout.cancel(countdownStop);
}

在这里我可以停止并开始但是现在我想在我的计时器上添加暂停按钮当用户点击暂停按钮我怎么能这样做我是新来的angularjs我在我的游戏中添加了一个按钮来暂停我的游戏

2 个答案:

答案 0 :(得分:1)

在按钮中调用onPause处理程序。

find . -type f -not -path "./gallery/*/full/*" -exec rm {} + && find . -type d -empty -delete

答案 1 :(得分:0)

这是一个可能的解决方案:

$scope.active = true;

$scope.start = function() {
    $scope.active = true;
    $scope.countdown();
};

$scope.countdown = function () {
    countdownStop = $timeout(function () {
        if ($scope.counter == 0) {
            $scope.stop();
            $scope.completeRound();

        }
        else {
            if ($scope.active) {
                $scope.counter--;
                $scope.countdown();
            }
        }
    }, 1000);
};

$scope.pause = function() {
    $scope.active = false;
};

$scope.stop = function () {
    $timeout.cancel(countdownStop);
}