Giter VIP home page Giter VIP logo

ngx-progressbar's Introduction

Angular Progressbar

A nanoscopic progress bar. Featuring realistic trickle animations to convince your users that something is happening!


npm npm Build Status npm

Table of Contents

Install it with npm

npm install ngx-progressbar --save

SystemJS

If you are using SystemJS, you should also adjust your configuration to point to the UMD bundle.

In your systemjs config file, map needs to tell the System loader where to look for ngx-progressbar:

map: {
  'ngx-progressbar': 'node_modules/ngx-progressbar/bundles/ngx-progressbar.umd.js',
}

Here is a working plunker.

Import NgProgressModule in the root module

import { NgProgressModule } from 'ngx-progressbar';

@NgModule({
  imports: [
    // ...
    NgProgressModule
  ]
})

In your root component (or any component that does not get destroyed)!

<ng-progress></ng-progress>

Add NgProgressService wherever you want to use the progressbar.

import {NgProgressService} from 'ngx-progressbar';

@Component({
 /**  */ 
})
export class SomeComponent {
  
  constructor(public progressService: NgProgressService) {
  }
  
  ngOnInit(){
      /** request started */
      this.progressService.start();
      this.http.get(url).subscribe(res){
          /** request completed */
          this.progressService.done();
      }
  }
}

NgProgressService options (functions):

  • NgProgressService.start() Shows the progress bar

  • NgProgressService.set(n) Sets a percentage n (where n is between 0-1)

  • NgProgressService.inc(n) Increments by n (where n is between 0-1)

  • NgProgressService.done() Completes the progress

NgProgressComponent options (inputs):

<ng-progress [positionUsing]="'marginLeft'" [minimum]="0.15" [maximum]="1"
             [speed]="200" [showSpinner]="false" [direction]="'rightToLeftIncreased'"
             [color]="'red'" [trickleSpeed]="250" [thick]="false" [ease]="'linear'"
></ng-progress>
  • [minimum]: between 0.0 to 1.0.

Progress initial starting value, default 0.08

  • [maximum]: between 0.0 to 1.0.

Progress maximum value, default 1.0

Progress animation ease, default linear.

  • [speed]: in milliseconds.

Transition speed, default 300.

  • [trickleSpeed]: in milliseconds.

Progress trickling speed, default 300.

  • [direction]: leftToRightIncreased, leftToRightReduced , rightToLeftIncreased, rightToLeftReduced.

Progressbar direction for LTR and RTL websites, default: leftToRightIncreased.

  • [positionUsing]: marginLeft, translate, translate3d.

Positioning method, default: marginLeft

  • [color]: any color format #1eb77f, brown, rgb(30, 183, 127).

Set the progressbar color, default: #29d

  • [showSpinner]: boolean

Display the spinner, default: true.

  • [thick]: boolean

A thicker size of the progressbar, default: false.

  • [toggle]: boolean

Toggle the progressbar (alternate to start/done), . default false.

If you only need a progressbar for multiple requests, there is a simple plug and play provider. It does the trick.

For Http

import { BrowserXhr, HttpModule } from '@angular/http';
import { NgProgressModule, NgProgressBrowserXhr } from 'ngx-progressbar';

@NgModule({
 providers: [
   // ...
   { provide: BrowserXhr, useClass: NgProgressBrowserXhr }
 ],
 imports: [
   // ...
   HttpModule,
   NgProgressModule
 ]
})

For HttpClient (Angular >= 4.3)

import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgProgressModule, NgProgressInterceptor } from 'ngx-progressbar';

@NgModule({
 providers: [
   // ...
   { provide: HTTP_INTERCEPTORS, useClass: NgProgressInterceptor, multi: true }
 ],
 imports: [
   // ...
   HttpClientModule,
   NgProgressModule
 ]
})

And just put the component in the template

 <ng-progress></ng-progress>

The progress will start and complete automatically with your HTTP requests. no need to use NgProgressService to call start()/done() manually.

If you identify any errors in the library, or have an idea for an improvement, please open an issue. I am excited to see what the community thinks of this project, and I would love your input!

Murhaf Sousli

Inspired by NProgress.js by Rico Sta. Cruz.

ngx-progressbar's People

Contributors

eliecharra avatar genuinefafa avatar murhafsousli avatar xinshangshangxin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.