(function () {
let MainController = function ($scope, $interval) {
let intervalToken;
const countdownStartNumber = 5;
const countdownEndAction = function(){
console.log("Countdown ended");
}
const decrementCountdown = function(){
$scope.countdown--;
if ($scope.countdown<1)
countdownEndAction();
}
$scope.resetCountdown = function(){
$scope.stopCountdown();
$scope.countdown=countdownStartNumber;
}
$scope.startCountdown = function(){
if (stopped){
intervalToken=$interval(decrementCountdown,1000,$scope.countdown);
stopped = false;
}
}
$scope.stopCountdown = function(){
stopped = true;
$interval.cancel(intervalToken);
}
$scope.countdown = countdownStartNumber;
let stopped=true;
$scope.startCountdown();
}
var app = angular.module("App", []);
app.controller("MainController", MainController);
})();