mujtaba-ahmad / ngx-countdown

1 stars 3 forks source link

ngx-countdown (Angular4 Countdown)

Angular 4 countdown is compatible with latest release of angular 4.x.x. Click here to open Demo App.

Functionality

  1. I can be applied anywhere in your web application.
  2. Given the time in seconds and time format, it start countdown in that format.
  3. Bootstrap and angular theme available, or you could use default theme and could style it accordingly.
  4. It also shows 2 callback functions OnStart and onComplete, one calls when countdown starts and other when countdown stops.

Installation

1. Update your app.module.ts file.

2. Add selector tag

  <app-count-down [time]="'10'" [object]="'2'" [singleFormat]="'hh:mm:ss'"></app-count-down>

add above selector to any component.html file, will pops-up countdown of 10 seconds. You can customize it further like this below

<app-count-down [time]="'15'" [object]="'2'" [singleFormat]="'hh-mm-ss'" (onStart)="onStart($event)" (onComplete)="onComplete($event)" [selectedtheme]="'material'"></app-count-down>
  import { Component } from '@angular/core';

  @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
  })
  export class AppComponent {
    title = 'app';
    onStart(data){
      console.log(data);
    }
    onComplete(data){
      console.log(data);
    }
  }

Above Code will pops-up countdown of 15 seconds with 'hh-mm-ss' format, and material theme. It will call onStart method when timer starts and calls onComplete method when timer ends.

3 Add Multiple timers

You can add multiple timers in single component like this

  import { Component } from '@angular/core';

  @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
  })
  export class AppComponent {
    title = 'app';
    onStart1(){
      console.log("Countdown 1 starts");
    }
    onComplete1(){
      console.log("Countdown 1 ends");
    }

    onStart2(){
      console.log("Countdown 2 starts");
    }
    onComplete2(){
      console.log("Countdown 2 ends");
    }
  }
  <app-count-down [time]="'10'" [singleFormat]="'hh-mm-ss'" (onStart)="onStart1()" (onComplete)="onComplete1()" [selectedtheme]="'material'"></app-count-down>

  <app-count-down [time]="'20'" [singleFormat]="'hh:mm:ss'" (onStart)="onStart2()" (onComplete)="onComplete2()" [selectedtheme]="'default'"></app-count-down>

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.

License

MIT