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

ng2-loading-spinner

v1.3.0

Published

customisable loading spinner for Angular applications

Downloads

1,618

Readme

npm version npm Build Status

Table of contents

Installation

npm install --save ng2-loading-spinner

Usage

Import Ng2LoadingSpinnerModule in your module

import { NgModule } from '@angular/core';
import { Ng2LoadingSpinnerModule } from 'ng2-loading-spinner'

@NgModule({
  imports: [ Ng2LoadingSpinnerModule.forRoot({}) ]
})
export class TestModule { }

then, use the ng2-loading directive on the element you want to have a spinner on:

<div class="card"
  [ng2-loading]="showSpinner">
    ...
</div>

the directive expects a boolean for showing and removing Loading spinner:

@Component({
    selector   : 'app.component',
    templateUrl: './app.component.html',
    styleUrls  : [ './app.component.css' ]
})
export class AppComponent {
    showSpinner: boolean = true;


    constructor() {
    	setTimeout(() => {
        	this.showSpinner = false;
        }, 1500);
    }
}

API

Input parameters

Input | Type | Required | Description | ------ | ----- | ----- | ----- | ng2-loading | boolean | Required | A boolean, which will determine when spinner is added to the DOM | config | INg2LoadingSpinnerConfig | Optional | Configuartion object for spinner. If no config options are set, the default config options will be used. | template | TemplateRef | Optional | If provided, the custom template will be shown in place of the default spinner animations. You can use this for rendering custom spinners instead of default spinner animations |

Configurable options

Config options can be set globally using the forRoot module import statement as well as being passed into each loader instance.Options passed to the instance of loader will override each global options.

Option | Required | type | Default value | Description | Examples | --- | --- | --- | --- | --- | ---- | animationType | Optional | string | ANIMATION_TYPES.fadingCircle | The spinner animation to be used. import ANIMATION_TYPES constant to select valid options. | ANIMATION_TYPES.chasingDots | backdropColor | Optional | string | rgba(0, 0, 0, 0.3) | Background color of backdrop element | 'red', 'rgb(120, 0, 171)', '#434343' | backdropBorderRadius | Optional | string | 0 | The border-radius property to be aplied to the spinner | '10px', '1rem', '50%' | spinnerColor | Optional | string | white | Color of spinner | 'red', 'rgb(120, 0, 171)', '#434343' | spinnerPosition | Optional | string | 'center' | Position the spinner into the host view | 'top', 'right', 'bottom', 'left', 'top-right', 'bottom-left' | spinnerSize | Optional | string | 'md' | Option that indicates size of spinner | 'sm', 'md', 'lg' | spinnerFontSize | Optional | string | | Option for controlling size of spinner.If provided spinnerSize option will be ignored | '10px', '1rem' |

Available spinner positions:

Position | ------ | center | top | right | bottom | left | top-right | left-right | top-left | bottom-left |

Available spinner sizes:

Size | ------ | xs | sm | md | lg | xl |

Examples

Example 1 - with custom configuration options

import { NgModule } from '@angular/core';
import { Ng2LoadingSpinnerModule } from 'ng2-loading-spinner'

@NgModule({
  imports: [ Ng2LoadingSpinnerModule.forRoot({
    backdropColor  : 'rgba(0, 0, 0, 0.3)',
    spinnerColor   : '#fff',
  }) ]
})
export class TestModule { }
import { Component } from '@angular/core';
import { ANIMATION_TYPES } from 'ng2-loading-spinner';
import { INg2LoadingSpinnerConfig } from 'ng2-loading-spinner';

@Component({
    selector   : 'app-example1',
    templateUrl: './example1.component.html',
    styleUrls  : [ './example1.component.css' ]
})

export class Example1Component {
    show = false;

    loadingConfig: INg2LoadingSpinnerConfig = {
        animationType  : ANIMATION_TYPES.dualCircle,
        spinnerPosition: 'left',
        backdropBorderRadius: '15px',
        spinnerSize: 'md',
        spinnerFontSize: '2rem'
    };


    constructor () {
    }

    showLoading() {
        this.show = true;
        setTimeout(() => {
            this.show = false;
        }, 1500);
    }
}
<button class="btn btn-dark"
        [ng2-loading]="show"
        [config]="loadingConfig"
        (click)="showLoading()">
   Show Spinner
</button>

Example2 - using custom template

import { Component } from '@angular/core';
import { ANIMATION_TYPES } from 'ng2-loading-spinner';
import { INg2LoadingSpinnerConfig } from 'ng2-loading-spinner';
import { AuthService } from '../auth.service'

@Component({
    selector   : 'app-example2',
    templateUrl: './example2.component.html',
    styleUrls  : [ './example2.component.css' ]
})

export class Example2Component {
    show = false;

    loadingConfig: INg2LoadingSpinnerConfig = {
        animationType  : ANIMATION_TYPES.dualCircle,
        backdropColor  : 'rgba(0, 0, 0, 0.3)',
        spinnerColor   : '#fff',
        spinnerPosition: 'center',
        backdropBorderRadius: '15px',
        spinnerSize: 'md',
        spinnerFontSize: '2rem'
    };


    constructor (private authService: AuthService) {
    }

    onLogin() {
        this.show = true;
        this.authService.login()
            .subscribe((res) => {
              this.show = false;
            })
    }
}

<form [ng2-loading]="show"
 [config]="loadingConfig"
 [template]="customTemplate">
    <input type="text" placeholder="username">
    <input type="password" placeholder="password">
    <button class="btn" (click)="onLogin()">Login</button>
<form>



<ng-template #customTemplate>
    <div class="align-items-center d-flex flex-column flex-direction">
        <p>Please wait</p>
        <div class="custom-loader"></div>
    </div>
</ng-template>

and style this custom loader in example2.component.css:

.custom-loader {
    ....
}