2
$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);
}

here i can able to stop and start but now i would like to add pause button to my timer when user clicks on pause button how i can i do that i am new to angularjs i was added one button in my game to pause my game

2 Answers 2

1

In a button call the onPause handler.

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

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

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

$scope.onPause = function(){
pause = !pause;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Dave jones and i would like to know some more whenever user click on pause button is it possible to open one box to show all options together like start stop resume and levels if possible please let me know and i tried with sweet alert and modal but its going to other page how can i do that
Not sure exactly what your trying to do, won't all controls be visible anyway? If you want to show something when paused you can just put that info in a div and show/hide with ng-show = "pause" that will only appear when pause is truthy.
yes but i would like to show that div as pop up and in that pop up i would like to show these options for user start or stop or reply or menu
0

Here is a possible solution:

$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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.