My angular timer function code in App.js look like :-
$scope.counter = 1000;
$scope.countdown = function () {
stopped = $timeout(function () {
$scope.counter--;
$scope.countdown();
}, 1000);
if ($scope.counter == 0) {
$timeout.cancel(stopped);
}
};
My counter directive look like :-
data.filter('formatTimer', function () {
return function (input) {
function z(n) { return (n < 10 ? '0' : '') + n; }
var seconds = input % 60;
var minutes = Math.floor(input / 60);
var hours = Math.floor(minutes / 60);
return (z(hours) + ':' + z(minutes) + ':' + z(seconds));
};
});
And in my html template code look like :-
<div class="col-xs-3 col-md-4 push" align="center" ng-init="countdown()">
<div class="alt_heade_text">
{{counter|formatTimer}}
</div>
</div>
Timer working fine for me but it decrease time(in seconds) 5 instead of 1, whats going wrong ???