17.0.0 • Published 4 months ago

ng-busy v17.0.0

Weekly downloads
3,244
License
MIT
Repository
github
Last release
4 months ago

Notice

1.x version is used for angular 5.x

6.x version is used for angular 6.x

7.x version is used for angular 7.x

8.x version is used for angular 8.x

9.x version is used for angular 9.x

10.x version is used for angular 10.x

11.x version is used for angular 11.x

NgBusy can show busy/loading indicators on any promise, or on any Observable's subscription.

Travis npm Downloads

demo

Rewritten from angular2-busy, and add some new features in terms of Angular 2.

Built with Angular 6.0.0

Demo

https://github.com/victos/angular-opensource/tree/master/projects/ng-busy/

Installation

npm install --save ng-busy

Link CSS

In angular.json:

  "styles": [
        ...
        "node_modules/ng-busy/src/style/busy.css",
        ...
      ],

Getting Started

Import the NgBusyModule in your root application module:

import {NgModule} from '@angular/core';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {NgBusyModule} from 'ng-busy';

@NgModule({
	imports: [
    	// ...
        BrowserAnimationsModule,
        NgBusyModule
    ],
	// ...
})
export class AppModule {}

Reference your promise in the ngBusy directive:

import {Component, OnInit} from '@angular/core';
import {HttpClient} from '@angular/common/http';

@Component({
    selector: 'some',
    template: `
        <div [ngBusy]="busy"></div>
    `
})
class SomeComponent implements OnInit {
    busy: Promise<any>;

    constructor(private http: HttpClient) {}

    ngOnInit() {
        this.busy = this.http.get('...').toPromise();
    }
}

Moreover, the subscription of an Observable is also supported:

// ...
import {Subscription} from 'rxjs';

// ...
class SomeComponent implements OnInit {
    busy: Subscription;

    // ...

    ngOnInit() {
        this.busy = this.http.get('...').subscribe();
    }
}

Directive Syntax

The ngBusy directive expects a busy thing, which means:

  • A promise
  • Or an Observable's subscription
  • Or an array of them
  • Or a configuration object In other words, you may use flexible syntax:
<!-- Collection syntax -->
<div [ngBusy]="[busyA, busyB, busyC]"></div>
<!-- Advanced syntax -->
<div [ngBusy]="{busy: busy, message: 'Loading...', backdrop: false, delay: 200, minDuration: 600}"></div>

Event

  • busyStop : Will be triggered when the busy is done
  • busyStart : Will be triggered when the busy comes out.

Usage

<!-- Simple syntax -->
<div [ngBusy]="..."  (busyStop)="onBusyStop()" (busyStart)="onBusyStart()"></div>

Options

OptionRequiredDefaultDetails
busyRequirednullA busy thing (or an array of busy things) that will cause the loading indicator to show.
messageOptional'Please wait...'The message to show in the indicator which will reflect the updated values as they are changed.
backdropOptionaltrueA faded backdrop will be shown behind the indicator if true.
templateOptionalA default template componentThe template can be a template or a component. If provided, the custom template will be shown in place of the default indicatory template. The scope can be augmented with a {{message}} field containing the indicator message text.
delayOptional0The amount of time to wait until showing the indicator. Specified in milliseconds.
minDurationOptional0The amount of time to keep the indicator showing even if the busy thing was completed quicker. Specified in milliseconds.
disableAnimationOptionalfalseDisable the animation when the spinner appear
wrapperClassOptional'ng-busy'The name(s) of the CSS classes to be applied to the wrapper element of the indicator.
templateNgStyleOptional{ }An object that will be assigned to the custom component assigned to template option, if one was configured (see example below in Overriding Defaults).

Overriding Defaults

The default values of options can be overriden by configuring the provider of the BusyModule.

In the root application module, you can do this:

import {NgModule} from '@angular/core';
import {NgBusyModule, BusyConfig} from 'ng-busy';
import {CustomBusyComponent} from '...'

@NgModule({
    imports: [
            ...
            NgBusyModule.forRoot(new BusyConfig({
                message: 'Don\'t panic!',
                backdrop: false,
                template: CustomBusyComponent,
                delay: 200,
                minDuration: 600,
                templateNgStyle: { "background-color": "black" }
            }))
        ],
        declarations: [
            ...
            CustomBusyComponent,
            ...
        ],
        entryComponents: [
            CustomBusyComponent
        ],
})
export class AppModule
@Component({
  selector: 'default-busy',
  template: `
    <div class="ng-busy-default-wrapper" [ngStyle]="templateNgStyle">
          <div class="ng-busy-default-sign">
            <div class="ng-busy-default-spinner">
              <div class="bar1"></div>
              <div class="bar2"></div>
              <div class="bar3"></div>
              <div class="bar4"></div>
              <div class="bar5"></div>
              <div class="bar6"></div>
              <div class="bar7"></div>
              <div class="bar8"></div>
              <div class="bar9"></div>
              <div class="bar10"></div>
              <div class="bar11"></div>
              <div class="bar12"></div>
            </div>
            <div class="ng-busy-default-text">{{message}}</div>
          </div>
        </div>
  `,
})
export class CustomBusyComponent {
  constructor(@Inject('instanceConfigHolder') private instanceConfigHolder: InstanceConfigHolderService) {
    }
  
    get message() {
      return this.instanceConfigHolder.config.message;
    }
}

Credits

Rewritten from devyumao's angular2-busy.

LICENSE

This project is licensed under the MIT license. See the LICENSE file for more info.

17.0.0

4 months ago

15.1.1

9 months ago

15.1.0

10 months ago

14.1.0

10 months ago

14.1.1

9 months ago

16.1.1

9 months ago

16.1.0

10 months ago

14.0.1

9 months ago

14.0.2

9 months ago

16.0.0

11 months ago

15.0.0

1 year ago

14.0.0

2 years ago

13.1.1

2 years ago

13.1.0

2 years ago

13.0.0

2 years ago

12.0.2

3 years ago

12.0.0

3 years ago

12.0.1

3 years ago

11.0.0

3 years ago

10.0.0

4 years ago

9.0.0

4 years ago

8.0.0

5 years ago

7.0.0

5 years ago

6.2.0

5 years ago

6.1.8

5 years ago

6.1.7

5 years ago

6.1.6

5 years ago

6.1.5

5 years ago

6.1.4

5 years ago

6.1.3

6 years ago

6.1.2

6 years ago

6.1.1

6 years ago

6.1.1-rc1

6 years ago

6.1.1-rc0

6 years ago

6.1.0

6 years ago

6.0.2-rc0

6 years ago

6.0.1-alpha1

6 years ago

6.0.2-alpha0

6 years ago

1.4.9-rc0

6 years ago

6.0.1

6 years ago

6.0.1-rc0

6 years ago

6.0.0

6 years ago

6.0.0-rc4

6 years ago

6.0.0-rc3

6 years ago

6.0.0-rc2

6 years ago

6.0.0-rc1

6 years ago

6.0.0-rc0

6 years ago

6.0.0-Alpha3

6 years ago

6.0.0-Alpha2

6 years ago

6.0.0-Alpha1

6 years ago

6.0.0-Alpha0

6 years ago

2.0.0-Alpha0

6 years ago

2.0.0-RC2

6 years ago

2.0.0-RC1

6 years ago

2.0.0-RC0

6 years ago

1.4.8

6 years ago

1.4.7

6 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.0

8 years ago