AngulsrJS LocalStorage CountDown Timer
A countdown timer that write the data into the localStorage of the browser. It's being used incase of: -You want to refresh the page and continue from where you left off. -You want to get notified when the time is up ( Event ) and trigger something.
$ npm install --save angularjs-localstorage-timer
Usage example
A full-featured working example can be found under the node_modules/angularjs-localstorage-timer/src/index.html
directory.
<!-- In your HTML file ( index.html ) -->
// Create your app with 'youtube-embed' dependencyvar myApp = angular
// Inside your controller...;
Events
;
Timer Functions
.start()
Stop the timer
Start
.stop()
Starting/Resuming the timer.
Start
.restart()
Restart the timer with the values given when creating the timer.
Timer won't start running, need to use start()
Restart
.update()
Update one of the parameters given to the new CountDownTimer()
's properties ( id, counter etc .. )
The update action will save the values into LocalStorage
as well, but won't restart the timer.
Timer won't start running, need to use start()
Update
Timer Information
.getCounter()
Will return the exiting counter value
$scopecounter = $scopeAppTimer;
.getLastUpdate()
Will return the "last updated" value that the timer has stored.
The value is a Date()
object.
$scopelastUpdate = $scopeAppTimer;
.getInfo()
Return as JSON
all the possible information stored in LocalStorage
.
Meaning the counter
, last_updated
, the timer's id
etc ..
$scopecounter = $scopeAppTimer;
.isTimePassed([integer])
Check if the time requested has passed since the .getLastUpdate() value Returns true / false
if $scopeAppTimer ...
Timer LocalStorage Actions
.reload()
So the reload()
isn't really there ... we need to write it on our own in our controller
as:
If $scope.properties.id
- is already found in LocalStorage
- the timer will be reloaded with the last counter.
But if the id
isn't found, it will create a new timer.
$scope { $scopeAppTimer = $scopeproperties; ; }
.remove()
Removing the timer entirly from LocalStorage
.
Remember that in order to continue from where we left off - the timer is always there ...
$scopeAppTimer;