I am using angularJS in my app. I have timer with $interval.
When I open browser, it works, but sometimes it`s stops.
I tried these cases:
- Open tab and wait for 15-20 minutes
- Open tab as not active and wait for 15-20 minutes
- Lock windows and wait again 15-20 minutes
In these cases all work well, but when I locked windows for 4 hours I found that timer stopped updating after an hour.
Also there are some cases that timer is being stopped when Windows is not locked, so can you help me with this issue?
function setTime() {
var now = new Date(timeStamp);
$scope.time = new Date(new Date( now.getTime() + (now.getTimezoneOffset() 60000)).getTime() + ($scope.timezoneOffset 60000));
if (!_intervalId) {
_intervalId = $interval(function () {
var tempTime = new Date().getTime();
timeStamp += (tempTime - currentTime) > 1100 || (tempTime - currentTime) < 900 ? 1000 : tempTime - _currentTime;
_currentTime = tempTime;
var now = new Date(timeStamp);
$scope.time = new Date(new Date( now.getTime() + (now.getTimezoneOffset() 60000)).getTime() + ($scope.timezoneOffset 60000))
}, 1000)
}
}
