• Stars
    star
    361
  • Rank 113,632 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Angular 2 component shows slim loading bar at the top of the page.

Angular 2 Slim Loading Bar npm version npm monthly downloads

Angular2 component shows slim loading bar at the top of the page of your application.

Build Status semantic-release Commitizen friendly Dependency Status devDependency Status Known Vulnerabilities

Follow me twitter to be notified about new releases.

Some of these APIs and Components are not final and are subject to change!

Installation

npm install ng2-slim-loading-bar --save

Demo

Simple examples using ng2-slim-loading-bar:

Online demo available here

Usage

If you use SystemJS to load your files, you might have to update your config:

System.config({
    map: {
        'ng2-slim-loading-bar': 'node_modules/ng2-slim-loading-bar/bundles/index.umd.js'
    }
});

1. Update the markup

  • Import the style.css file into your web page
  • Add <ng2-slim-loading-bar></ng2-slim-loading-bar> tag in template of your application component.

2. Import the SlimLoadingBarModule

Import SlimLoadingBarModule.forRoot() in the NgModule of your application. The forRoot method is a convention for modules that provide a singleton service.

import {BrowserModule} from "@angular/platform-browser";
import {NgModule} from '@angular/core';
import {SlimLoadingBarModule} from 'ng2-slim-loading-bar';

@NgModule({
    imports: [
        BrowserModule,
        SlimLoadingBarModule.forRoot()
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

If you have multiple NgModules and you use one as a shared NgModule (that you import in all of your other NgModules), don't forget that you can use it to export the SlimLoadingBarModule that you imported in order to avoid having to import it multiple times.

@NgModule({
    imports: [
        BrowserModule,
        SlimLoadingBarModule.forRoot()
    ],
    exports: [BrowserModule, SlimLoadingBarModule],
})
export class SharedModule {
}

3. Use the SlimLoadingBarService for your application

  • Import SlimLoadingBarService from ng2-slim-loading-bar in your application code:
import {Component} from '@angular/core';
import {SlimLoadingBarService} from 'ng2-slim-loading-bar';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="startLoading()">Start Loading</button>
        <button (click)="stopLoading()">Stop Loading</button>
        <button (click)="completeLoading()">Complete Loading</button>
        <ng2-slim-loading-bar></ng2-slim-loading-bar>
    `
})
export class AppComponent {

    constructor(private slimLoadingBarService: SlimLoadingBarService) { }

    startLoading() {
        this.slimLoadingBarService.start(() => {
            console.log('Loading complete');
        });
    }

    stopLoading() {
        this.slimLoadingBarService.stop();
    }

    completeLoading() {
        this.slimLoadingBarService.complete();
    }
}

3. Customize the the ng2-slim-loading-bar for your application

You can use the following properties to customize the ng2-slim-loading-bar component in your template:

  • color - The color of loading bar. Default is firebrick. It can be any CSS compatible value.
  • height - The height of loading bar. Default value is 2px.
  • show - The flag helps hide and show the loading bar. Default value is true.

Example: <ng2-slim-loading-bar color="blue" height="4px"></ng2-slim-loading-bar>

4. Manage the loading bar

You can use the following properties to customize the SlimLoadingBar via instance of SlimLoadingBarService:

  • color - The color of loading bar.
  • height - The height of loading bar.
  • visible - The flag helps hide and show the loading bar, false for hidden and true for visible.

You can use the following methods to control the SlimLoadingBar via instance of SlimLoadingBarService:

  • start - Start the loading progress. Use the callback function as an parameter to listed the complete event.
  • stop - Stop the loading progress. This method pause the current position of loading progress.
  • reset- Reset the position of loading progress to 0.
  • complete - Set the progress to 100% and hide the progress bar.

5. Events handling

You can hook up with our different types of events thrown.

  • SlimLoadingBarEventType.PROGRESS
  • SlimLoadingBarEventType.HEIGHT
  • SlimLoadingBarEventType.COLOR
  • SlimLoadingBarEventType.VISIBLE

you can subscribe to these events types by simplying doing this

 constructor(private _loadingBar: SlimLoadingBarService) {
    this._loadingBar.events.subscribe((item:SlimLoadingBarEvent) => console.log(item));
   }

where item returned is of SlimLoadingBarEvent {type: SlimLoadingBarEventType, value: any}

Credits

Inspired by ngProgress.js

License

MIT

More Repositories

1

ng2-dnd

Angular 2 Drag-and-Drop without dependencies
TypeScript
845
star
2

ng2-toasty

Angular2 Toasty component shows growl-style alerts and messages for your app.
TypeScript
283
star
3

angular.dart.ui

Port of Angular-UI to Dart.
Dart
101
star
4

ng2-webpack-demo

A minimal Angular2 playground using TypeScript and Webpack loader to demonstrate the use of different libraries
TypeScript
85
star
5

dart_web_toolkit

Dart Web Toolkit (DWT) is a development toolkit for building and optimizing complex browser-based applications inspired by GWT.
Dart
71
star
6

ionic2-firebase-webrtc

WebRTC with authentication from Firebase build on Ionic 2
TypeScript
45
star
7

angular.dart.material

Material Design implementation on Angular Dart.
CSS
15
star
8

ng2-systemjs-demo

A minimal Angular2 playground using TypeScript and SystemJS loader to demonstrate the use of ng2-dnd, ng2-toasty and ng2-slim-loading-bar
TypeScript
13
star
9

lost_dart

Lost Dart is lightweight dependency injection framework for Dart client and server applications.
Dart
12
star
10

ionic2-pubnub-chat

Chat implementation on Ionic 2 based on PubNub solution
TypeScript
10
star
11

dart_web_toolkit_showcase

Dart Web Toolkit (DWT) Showcase
Dart
9
star
12

angular.dart.ui.demo

Demo project demonstrating the Dart Angular UI elements
JavaScript
9
star
13

ng2-navigation

A configurable, responsive navbar and sidebar components for Angular 2 projects.
TypeScript
4
star
14

recaptcha

ReCaptcha is a Dart library for interfacing with ReCaptcha service
Dart
4
star
15

learning_bootstrap4_angular2

Source code for "Web Development with Bootstrap 4 and Angular 2 - Second Edition", Packt Publishing
TypeScript
4
star
16

dart_web_toolkit_cell

Data presentation widgets for the Dart Web Toolkit
Dart
3
star
17

monomer

A Monomer is Polymer UI library.
Dart
3
star
18

js_proxy

Lite proxy to work with JavaScript in simple and comfortable fashon
Dart
2
star
19

angular.dart.material.demo

Demo project shows Bootstrap Material Design implementation on angular_material library.
CSS
2
star
20

ng2-intro

Introductions for websites and features with a step-by-step guide for Angular 2 projects.
TypeScript
1
star
21

ng2-mockup

Angular 2 tool to create mockups
JavaScript
1
star