Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anil1712 opened this issue Dec 23, 2013 · 10 comments
Open

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

anil1712 opened this issue Dec 23, 2013 · 10 comments

Comments

@anil1712
Copy link

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; });

@siddii
Copy link
Owner

siddii commented Dec 23, 2013

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 #34 (comment) associated to that plunkr.

@anil1712
Copy link
Author

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
Copy link
Author

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

@siddii
Copy link
Owner

siddii commented Dec 26, 2013

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

@anil1712
Copy link
Author

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

@siddii
Copy link
Owner

siddii commented Dec 27, 2013

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.

@anil1712
Copy link
Author

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.

@balthazar
Copy link

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.

@ahmedkhaledmohamed
Copy link

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

@dedpnd
Copy link

dedpnd commented Dec 20, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants