angular-timer icon indicating copy to clipboard operation
angular-timer copied to clipboard

Not able to update timer value inside ajax success response block.

Open anil1712 opened this issue 11 years ago • 10 comments
trafficstars

Hi, I want to put the timer value from my db, so that's why I am making a ajax call and the response will replace the value of the timer. but its not working, here is my code:

<timer start-time="startTime" interval="100" countdown="students.countdown"> <strong>{{hours}} hours, {{minutes}} minutes, {{seconds}} second</strong> </timer>

dashboardFactory.getTimerTime().then(function(response) { $scope.startTime = response.time; });

anil1712 avatar Dec 23 '13 21:12 anil1712

You cannot set the timer's start time from an asynchronous call after directive compilation (page load). You need to re-compile the directive after the async response & attach it to the scope. Here is a plunkr that kinda does that - http://plnkr.co/edit/GjKSSVM1x2UQC2gLQeGo?p=preview

The original issue https://github.com/siddii/angular-timer/issues/34#issuecomment-30958303 associated to that plunkr.

siddii avatar Dec 23 '13 21:12 siddii

Thanks, its working but timer is still not working properly, actually when user logged I stored the new Date().getTime() + 180*60*1000 in my DB and the stored value look something like this 1387872383960. So the timer value initialize from DB, it will remain same if you refresh the page, but when I refreshed the page after some time like after 10 minutes then it also refreshed the timer. Please help me Siddi and let me know if I am doing something wrong.

anil1712 avatar Dec 24 '13 05:12 anil1712

Siddii, any solution for above mentioned problem. Please give me any suggestion for that.

anil1712 avatar Dec 26 '13 09:12 anil1712

Can you send a plunkr for your issue? I don't quite get whats happening here.

siddii avatar Dec 26 '13 13:12 siddii

Actually I want to create a 3 hours countdown timer for Online Exam which should not reset on page refresh. When user logged in I am storing timer start-time value in DB. So start time will comes from DB.

Please check this plunk and help me to out of it http://plnkr.co/edit/DaQdtOj7OcT4BaJuqYAo?p=preview

anil1712 avatar Dec 27 '13 07:12 anil1712

I don't see anything new in that plunkr. It looks like the same one I showed earlier.

Note that when you refresh the page/view the controller gets initialized & display values gets reset whether in a directive or not. I am guessing you probably need to store the displayed time in the DB & re-initialize directive on page load again.

siddii avatar Dec 27 '13 14:12 siddii

Yes you are right, I am storing the timer value (in milliseconds) in DB and initialize it on page load, So the value will remain same on every page load, but my countdown timer is not working. I want a 3 hours countdown timer for online exam.

anil1712 avatar Dec 27 '13 16:12 anil1712

You could also use ng-if on your timer element to check for your startTime variable. This way, the directive will only be initialised when you have your date, and it will work.

balthazar avatar May 01 '15 13:05 balthazar

@Apercu thanks for the answer, i will refer to your answer in some other issues.

ahmedkhaledmohamed avatar Jun 03 '16 09:06 ahmedkhaledmohamed

The example does not work. =) Working example: http://plnkr.co/edit/QFEdzpOhRbInH7HQzLVr?p=preview

dedpnd avatar Dec 20 '16 12:12 dedpnd