All Projects → jmandreslopez → ng2-odometer

jmandreslopez / ng2-odometer

Licence: MIT license
Odometer for Angular2

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to ng2-odometer

Angular4 Docker Example
Efficiently Dockerized Angular CLI example app
Stars: ✭ 212 (+863.64%)
Mutual labels:  angular2, angular-cli
cloud-speech-and-vision-demos
A set of demo applications that make use of google speech, nlp and vision apis based in angular2
Stars: ✭ 35 (+59.09%)
Mutual labels:  angular2, angular-cli
Angular5 Seed
Angular5 Seed for Application
Stars: ✭ 222 (+909.09%)
Mutual labels:  angular2, angular-cli
Ng Pi Admin
Angular admin http://treesflower.com/ng-pi-admin
Stars: ✭ 131 (+495.45%)
Mutual labels:  angular2, angular-cli
YOP
Year Of Programmers: 개발자 회고록 아카이브
Stars: ✭ 42 (+90.91%)
Mutual labels:  angular2, angular-cli
Paper Kit 2 Angular
Free Bootstrap 4 UI Kit for Angular 2+
Stars: ✭ 133 (+504.55%)
Mutual labels:  angular2, angular-cli
Ng Pokedex
🐵 Pokedex progressive web app built with Angular
Stars: ✭ 245 (+1013.64%)
Mutual labels:  angular2, angular-cli
Clever Bootstrap 4 Admin Template With Angularjs Angular 2 Support
Clever is Boostrap 4 Admin Template with Angular 2 and AngularJS support
Stars: ✭ 98 (+345.45%)
Mutual labels:  angular2, angular-cli
ng2-stompjs-demo
Angular 2 demo using stomp.js in Typescript
Stars: ✭ 42 (+90.91%)
Mutual labels:  angular2, angular-cli
ng2-mqtt-demo
Angular 2 demo using MQTT.js in Typescript
Stars: ✭ 32 (+45.45%)
Mutual labels:  angular2, angular-cli
Ng Packaged
An Angular library packaged by ng-packagr
Stars: ✭ 109 (+395.45%)
Mutual labels:  angular2, angular-cli
laravel5Angular4
Laravel 5.4 & Angular 4.3.4
Stars: ✭ 37 (+68.18%)
Mutual labels:  angular2, angular-cli
Anvel
Angular 2 Laravel Starter Kit
Stars: ✭ 102 (+363.64%)
Mutual labels:  angular2, angular-cli
Angular2 Crud Rest
Sample Angular (2.x and 4.x) app: CRUD example + routing
Stars: ✭ 152 (+590.91%)
Mutual labels:  angular2, angular-cli
Angular4 Primeng Admin
angular4-primeng-admin @angular/cli开发的后台模板
Stars: ✭ 99 (+350%)
Mutual labels:  angular2, angular-cli
Blog Angular
Angular 笔记
Stars: ✭ 238 (+981.82%)
Mutual labels:  angular2, angular-cli
Angular Full Stack
Angular Full Stack project built using Angular, Express, Mongoose and Node. Whole stack in TypeScript.
Stars: ✭ 1,261 (+5631.82%)
Mutual labels:  angular2, angular-cli
Coreui Free Angular Admin Template
CoreUI Angular is free Angular 2+ admin template based on Bootstrap 4
Stars: ✭ 1,279 (+5713.64%)
Mutual labels:  angular2, angular-cli
AuthGuard
Example repo for guarding routes post
Stars: ✭ 42 (+90.91%)
Mutual labels:  angular2, angular-cli
angular2-node-fb-login
Demo application that shows how to enable Facebook login with Angular 2 on frontend and Node.js/Express on backend
Stars: ✭ 55 (+150%)
Mutual labels:  angular2, angular-cli

ng2-odometer npm version MIT license

Odometer for Angular2 that wraps HubSpot's Odometer http://github.hubspot.com/odometer/docs/welcome/

Quick Start

npm install ng2-odometer --save

Table of contents

Setup

First you need to install the npm module:

npm install ng2-odometer --save

Then add the Ng2OdometerModule to the imports array of your application module.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Ng2OdometerModule } from 'ng2-odometer'; // <-- import the module
import { AppComponent} from './app.component';

@NgModule({
    imports: [
      BrowserModule, 
      Ng2OdometerModule.forRoot() // <-- include it in your app module
    ], 
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {
    //
}

Usage

Use the <ng2-odometer></ng2-odometer> component to create an odometer. The number is required attribute. The number represents the limit at which the odometer will travel. The config an object with the configuration properties, this is NOT required.

@Component({
   selector: 'main-element',
   template: `
        ...
        <ng2-odometer [number]="number" [config]="{ }"></ng2-odometer>
        <!-- Further content here -->
        ...
   `
})
export class MainElementComponent {
  public number: number = 1000;
}

When on manual mode ([config]="{ auto: false }"), you can update the number attribute and that will trigger an odometer update right away. The observable is an Observable which will be used as a trigger for the odometer when on manual mode.

@Component({
   selector: 'main-element',
   template: `
        ...
        <ng2-odometer [number]="number" [config]="{ auto: false }" [observable]="observable"></ng2-odometer>
        <!-- Further content here -->
        ...
   `
})
export class MainElementComponent {
  public number: number = 1000;
  public observable: Observable<boolean>;
  private observer: Observer<boolean>;
  
  constructor() {
    this.observable = new Observable<boolean>((observer: any) => this.observer = observer).share();

    // Trigger odometer after 2s
    setTimeout(() => this.observer.next(true), 2000);
  }
}

Configuration

The component accepts either a [config]="{ ... }" attribute with an object with all the configurable attribues or independent attributes for each configuration.

Option Type Default Description
animation string 'slide' Animation effect type.
Options: 'slide', 'count'
format string '(,ddd)' Format to apply on the numbers.
Format - Example:
(,ddd) - 12,345,678
(,ddd).dd - 12,345,678.09
(.ddd),dd - 12.345.678,09
( ddd),dd - 12 345 678,09
d - 12345678
theme string 'default' The desired theme.
Options: 'default', 'minima', 'digital', 'car', 'plaza', 'slot-machine', 'train-station'
value number 0 Initial value of the odometer
auto boolean true Setup auto or manual mode for the odometer
@Component({
   selector: 'main-element',
   template: `
        ...
        <ng2-odometer 
            [number]="1000" 
            [observable]="observable" 
            [config]="config"></ng2-odometer>
        <!-- Further content here -->

        <ng2-odometer 
            [number]="1000" 
            [observable]="observable"
            [config]="{ animation: 'count', format: 'd', theme: 'car', value: 50, auto: false }">
        </ng2-odometer>
        <!-- Further content here -->

        <ng2-odometer 
            [number]="1000"  
            [observable]="observable"
            [animation]="'count'"
            [format]="'d'"
            [theme]="'car'"
            [value]="0",
            [auto]="false">
        </ng2-odometer>
        <!-- Further content here -->
        ...
   `
})
export class MainElementComponent {
    public config = {
        animation: 'count', 
        format: 'd', 
        theme: 'car', 
        value: 50,
        auto: true,
    }

    ...
}

If you add both, the [config] and any independent configuration, the independent config will overwrite the [config] object.

Demo

The demo subfolder contains a project created with angular-cli that has been adapted to showcase the functionality of ng2-odometer. To execute the code follow this steps:

// Go the the demo folder
cd demo

// Install dependencies
npm install

// Run the server
ng serve

Then go to http://localhost:4200 to check the demo running.

TODO:

  • Update to Angular4
  • Add tests to the library and demo
  • Add new themes
  • Create a Directive also

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].