npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-loading-bar

v0.0.10

Published

Automatic page loading / progress bar for Angular 2

Downloads

78

Readme

@ngx-loading-bar

A fully automatic loading bar with zero configuration for angular app (http, http-client and router).

Packages

Demo

  • online demo: https://angular-sypacw.stackblitz.io
  • demo-app: Example utilizing all @ngx-loading-bar libraries.

Quick Start

1. Install one or all @ngx-loading-bar libraries:

  # if you use `@angular/common/http`
  npm install @ngx-loading-bar/http-client --save

  # if you use `@angular/http`
  npm install @ngx-loading-bar/http --save

  # if you use `@angular/router`
  npm install @ngx-loading-bar/router --save

  # to manage loading-bar manually
  npm install @ngx-loading-bar/core --save

2. Import the installed libraries (LoadingBarHttpClientModule, LoadingBarHttpModule, LoadingBarRouterModule or LoadingBarModule):

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client';

// for Http import LoadingBarHttpModule:
// import { LoadingBarHttpModule } from '@ngx-loading-bar/http';

// for Router import LoadingBarRouterModule:
// import { LoadingBarRouterModule } from '@ngx-loading-bar/router';

// for Core import LoadingBarModule:
// import { LoadingBarModule } from '@ngx-loading-bar/core';

import { AppComponent } from './app';

@NgModule({
  ...
  imports: [
    ...

    LoadingBarHttpClientModule

    // for HttpClient use:
    // LoadingBarHttpModule,

    // for Router use:
    // LoadingBarRouterModule

    // for HttpClient use:
    // LoadingBarHttpClientModule

    // for Core use:
    // LoadingBarHttpClientModule.forRoot()
  ],
})
export class AppModule {}

3. Include ngx-loading-bar in your app component:

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

@Component({
  selector: 'app',
  template: `
    ...
    <ngx-loading-bar></ngx-loading-bar>
  `,
})
export class AppComponent {}

4. include the supplied CSS file (or create your own).

Manually manage loading service

1. Import the LoadingBarModule

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

import { LoadingBarModule } from '@ngx-loading-bar/core';

@NgModule({
  ...
  imports: [
    ...

    LoadingBarModule.forRoot(),
  ],
})
export class AppModule {}

2. Inject/Use LoadingBarService

import { Component } from '@angular/core';
import { LoadingBarService } from '@ngx-loading-bar/core';

@Component({
  selector: 'app',
  template: `
    ...
    <ngx-loading-bar></ngx-loading-bar>
    <button (click)="startLoading()">start</button>
    <button (click)="stopLoading()">stop</button>
  `,
})
export class App {
    constructor(private loadingBar: LoadingBarService) {}

    startLoading() {
        this.loadingBar.start();
    }
    
    stopLoading() {
        this.loadingBar.complete();
    }
}

Advanced

When you import LoadingBarHttpModule, http service observables become hot. That means that a HTTP request is sent as soon as a call to http.get (for example) has been made.


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


@Component({
    selector: 'ng-loading-bar-app',
    templateUrl: './app.html',
})
export class App {
    private request$;

    constructor(private _http: Http) {
        // http request is sent here
        this.request$ = _http.get('/app/heroes');
    }

    startLoadingBarHttpRequest() {
        if (false) {
            // Request has been sent to server 
            this.request$.subscribe();
        }
    }
}

This behavior is because the Loading bar module overrides default http service by setting up a subscription to the request. This subscription fires up the HTTP request.

If this behavior doesn't suit you, you should manage loading bar manually as in the component startHttpRequest above.

Credits