Reputation: 15026
I have a simple controller that is intended to make a simple count-down.
When I run this code, all I get is a single "tick" in the console. I would expect one tick every 5 milliseconds.
.controller('Countdown', function($scope, $timeout){
$scope.endtime = new Date('May 5, 2014 00:00:00');
var countup = function() {
$scope.currtime = new Date();
$scope.timeleft = $scope.endtime-$scope.currtime;
console.log('tick');
};
$timeout(countup, 5);
});
Upvotes: 0
Views: 70
Reputation: 5826
As Michael said you should use $interval
Or you can do like this.
.controller('Countdown', function($scope, $timeout){
$scope.endtime = new Date('May 5, 2014 00:00:00');
var countup = function() {
$scope.currtime = new Date();
$scope.timeleft = $scope.endtime-$scope.currtime;
console.log('tick');
$timeout(countup, 5); // Recursive technique
};
});
Upvotes: 3