Skip to content

Instantly share code, notes, and snippets.

@lossendae
Created January 16, 2014 11:49
Show Gist options
  • Save lossendae/8453632 to your computer and use it in GitHub Desktop.
Save lossendae/8453632 to your computer and use it in GitHub Desktop.
AngularJS timer with pause
var Controller = function($timeout){
var timer = 10000;
$scope.remaining = timer / 1000;
$scope.startTimer = function(){
$scope.timeout = $timeout(function() {
$scope.remaining--;
$scope.remaining > 0 ? $scope.startTimer() : $scope.finished('Finished!');
}, 1000);
};
$scope.stopTimer = function(){
$timeout.cancel($scope.timeout);
};
$scope.startTimer();
$scope.finished = function(msg){
console.info(msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment