angular-timer
angular-timer copied to clipboard
Interval < 1000 does not work
The modulus of "adjustment" needs to be adjustable (heh heh) or flexible for <1000 intervals:
var tick = function () {
$scope.millis = new Date() - $scope.startTime;
var adjustment = $scope.millis % 1000;
//We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5
$scope.timeoutId = setTimeout(function () {
tick();
$scope.$digest();
}, $scope.interval - adjustment);
If $scope.interval is less than 1000ms, and adjustment is greater than the interval, then you will get a negative integer for the setTimeout function.
For my application, timer accuracy isn't as important at this stage but it is worth taking note of. I have temporarily removed "adjustment" from my timeout in order to achieve a functional interval.
$scope.timeoutId = setTimeout(function () {
tick();
$scope.$digest();
}, $scope.interval);
+1 ! intervals < 1000 don't work ...