angular-timer
angular-timer copied to clipboard
finish-callback does not work with end-time in <timer>
finish-callback
only works with countdown
. finish-callback
does not work with end-time
in <timer>
. When finish-callback
is added, the callback immediately triggered .
I just ran into a similar issue. It does seem to work with end-time
for me. It triggers the callback immediately if end-time
is in the past, and that applies within a digest cycle and everything works as expected. However, once the end time is actually reached (as in it happens after the page has already loaded), it seems to trigger the callback but not $apply() the changes, so angular is not aware of them.
Since in one scenario a digest is already running, but not in the other, I ended up doing this as a work around so that the changes in this function are always applied, but it doesn't conflict with an existing digest if it exists:
$scope.myCallbackFunction = function() {
$timeout(function() {
// Code
});
}
This is the directive tag:
<timer finish-callback="myCallbackFunction()" end-time="1452126400000" max-time-unit="'hour'" interval="1000">
....
Seems a little dirty, but gets the job done and works as expected in all cases. Maybe the timeout should be extracted into directive itself, or maybe it could be handled another way all together. I'll try to dig into the code later if I have time and see if I can get a better solution.
Let me know if you found a better solution for your issue.
My app shows, thanks to finish-callback, an "expired" alert if end-time is in the past. It works great if timer tag is in one static place (it means, not inside ng-repeat). I have a ng-repeat list which prints all homeworks end-times, if all times are in present there aren't problems. But if one time is in past, suddenly ALL times are in past, which is incorrect.
I've made your workaround (for ng-repeat list, like you, in controller) but without success.
+1 Please fix this bug