ng2-countdown (Angular2 Countdown)
Angular2 contdown is complatible with latest release of angular 2.x.x.
- I can be applied anywhere in your web application.
- Given the time in seconds and time format, it start countdown in that format.
- Bootstrap and angular theme available, or you could use defauld theme and could style it accordingly.
- It also shows 2 callback functions OnStart and onComplete, one calls when condown starts and other when countdown stops.
Follow these steps:
1. Update your
Add following line in map:
-and in packages:
packages://...'ng2-countdown':main: './index.js'defaultExtension: 'js'
2. Update the index.html
- Import style into your index.html.
node_module/ng2-countdown/app/assets/css/style.css- Contains the styling of countdown. Please copy that and paste that in your assets folder and include in your index.html file, or could link this css file directly in you index.html by giving path of style.css file present in node_modules/ng-countdown/app/assets/css/style.css
3. Import the
Import Components in the NgModule of your application as shown below:
Adding this sevice in ngModule make it accessible in whole project. and mainly it service we were setting countdown configration so making it signleton by adding it in main module will help.
CountdownOptions for you application
Now we need to set countdownOptions like theme, time format, onStart callback and onComplete callback. in our main Component like AppComponent in my case.
- format supported -All formats uptill days. for example hh:mm:ss, hⓂ️s etc If you use onStart and onComplete callback here they will be generic and will be called on start and on complete of countdown. and will return countdown object. Will explain countdown object in a while.
you should call setCoundownOptions() function and pass countdownOptions object as parameter in setCoundownOptions(countdownOptions). Else countdownOptions wont appear.
Please review below code.
CountdownService in your application
Now CountdownOptions are properly configure and set,we could user countdown anywhere in our app, like in below code i am using it in my main component after configuring countdownOptions.
Please review below code.
Above code will show two countdowns. first with 10 seconds and second with 20 seconds. You could define onStart and onComplete events on every countdown element, and it will run as well when counter starts or completes. Inorder if anyone want to perform anything when counter ends. And they are independent of each other, Every counter have its on events.