data.staus
是
complete
angular.module('timerApp', ['timerApp.controllers']);
angular.module('timerApp.controllers', []).controller('timerController', ['$scope', '$interval',
function($scope, $interval) {
var timer;
var time = 10;
$scope.countdown = time;
$scope.stopTimer = function()
{
$interval.cancel(timer);
};
$scope.startTimer = function() {
timer = $interval(function() {
$scope.countdown--;
//res is response from my backend
var data = res;
if (data.status = "complete"){
$scope.timerFlag = true;
}
}, 15000, time);
timer.then(function() {
$scope.countdown = time;
});
};
}
$scope.$watch(){
if($scope.timerFlag == true){
$scope.stopTimer();
}
}
]);