0.3.1 • Published 7 years ago

ngx-countto v0.3.1

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

ngx-countto

Angular 2+ component that counts up to a specified number. And accompanying service to trigger the action at a desired time or event. Supports multiple instances and different starting times.

Preview in Plunker

Installation

NPM

To install this library, run:

$ npm install ngx-countto --save

Usage

Add the component in your Angular application's template:

<!-- You can now use your library component in app.component.html -->
<h1>{{title}}</h1>
<ngx-countto [to]=100></ngx-countto>

And in your Angular AppModule, import the library then trigger the counting by calling CountToService's function start() anywhere from your application logic:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

// Import the library
import { CountToModule, CountToService } from 'ngx-countto';

@NgModule({
  declarations: [ AppComponent ],
  imports: [
    BrowserModule,
    // Specify the library as an import
    CountToModule
  ],
  providers: [ CountToService ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

@Component()
class AppComponent implements OnInit {
  // Inject the service into your component
  constructor(private counttoService: CountToService) {}
  ngOnInit() {
    // Start the counting via the service
    this.counttoService.start();
  }
}

Parameters

ParameterTypeDefaultDescription
idstringcounttoElement ID of the component. For multi-component support
fromnumber0Starting number (Not yet supported)
tonumberfrom + 10Ending number
durationnumber?Duration (Not yet supported)

Examples

<ngx-countto [from]=1 [to]=100></ngx-countto>
<ngx-countto [id]="'countto_01'" [to]=18000></ngx-countto>
class AppComponent implements OnInit {

  constructor(private counttoService: CountToService) {}
  ngOnInit() {
    this.counttoService.start();

    setTimeout(() => {
      this.counttoService.start('countto_01');
    }, 2000);
  }
}

License

MIT © Kris Nyunt