I'm a beginner AngularJS/html user who's been trying to find a code snippet to make a clock/time item for a web app.
A web search did not provide straight-forward results as easily as I would expect them for something so trivial, so I thought I would post this question to get some answers and also make this easier to find for others.
I have posted my solution but want to see if there is anything nicer out there before choosing an answer!
Just trying to improve Armen's answer. You can use the
$interval
service to setup a timer.I created a small directive to display a digital clock. The self invoking function is needed because there would be one second delay when rendering the clock.
This works quite nicely for me and I think is easy to follow for noobs. See it in action here
JavaScript:
HTML:
Don't forget to include angularJS and the 'ng-app' in your body tag.
This is the simplest answer I could come up with using $interval:
Example
The JS
The HTML
Here is a timer implementation using the same $interval registration function to register a new interval on start, and cancel the interval on stop.
WARNING! It is not possible to bind to the $interval delay parameter
Example
The JS
The HTML
You can use this code. It's more simple.