Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-ui-loader

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-ui-loader

An all-in-one and fully customizable loader/spinner for Angular 5+ (5+ and 6+ are tested) applications. It supports foreground, background spinner/loader and indicative progress bar.

  • 1.1.9
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm version Build Status npm npm npm

ngx-ui-loader

An all-in-one and fully customizable loader/spinner for Angular 5+ (5+ and 6+ are tested) applications. It supports foreground, background spinner/loader and indicative progress bar.

ngx-ui-loader-demo

Available spinners:

ngx-ui-loader-spinners

Features

  • Show foreground loader with progress bar
  • Show background loader with different id for different tasks
  • Be able to add logo, loading text
  • Be able to change position of spinners, logo and loading text. NOTE: When they are all set to center-center, the gap between them are adjusted via gap properties. Other position types are is overlap. E.g. If the position of foreground spinner and logo are set to bottom-center, they are overlap each other.
  • Be able to change color and size of logo, spinners and progress bar
  • Be able to change the direction of progress bar

Table Of Contents

Demo

Live demo here.

Play with ngx-ui-loader here on stackblitz.

If you like it, please star on Github.

Installation

Install ngx-ui-loader via NPM, using the command below.

NPM

$ npm install --save ngx-ui-loader

Or Yarn

$ yarn add ngx-ui-loader

Getting started

Import the NgxUiLoaderModule in your root application module AppModule:


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

import { AppComponent } from './app.component';

import { NgxUiLoaderModule } from  'ngx-ui-loader';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    // Import NgxUiLoaderModule
    NgxUiLoaderModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

After importing the NgxUiLoaderModule, use ngx-ui-loader component in your root app template:

<ngx-ui-loader></ngx-ui-loader>

Add NgxUiLoaderService service wherever you want to use the ngx-ui-loader:

import { Component, OnInit } from '@angular/core';
import { NgxUiLoaderService } from 'ngx-ui-loader'; // Import NgxUiLoaderService

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  constructor(private ngxService: NgxUiLoaderService) { }

  ngOnInit() {
    this.ngxService.start(); // start foreground loading with 'default' id

    // Stop the foreground loading after 5s
    setTimeout(() => {
      this.ngxService.stop(); // stop foreground loading with 'default' id
    }, 5000);

    // OR
    this.ngxService.startBackground('do-background-things');
    // Do something here...
    this.ngxService.stopBackground('do-background-things');
  }
}

API - NgxUiLoaderService

  • NgxUiLoaderService.start([id]='default') Starts a foreground loader with progress bar. Users cannot interact with the page when the loader is showed.
  • NgxUiLoaderService.stop([id]='default') Stops a foreground loader with progress bar.
  • NgxUiLoaderService.startBackground([id]='default') Starts a background loader. Users can interact with the page when the loader is showed.
  • NgxUiLoaderService.stopBackground([id]='default') Stops a background loader.
  • NgxUiLoaderService.getDefaultConfig() Returns the default configuration object of ngx-ui-loader.
  • NgxUiLoaderService.getStatus() Returns an object including waitingForeground and waitingBackground properties.
  • NgxUiLoaderService.stopAll() Stops all foreground and background loaders.

Custom Configuration

You can configure ngx-ui-loader in the template as below:

Import the constant SPINNER_TYPES from ngx-ui-loader in your controller. Then in your template:

<ngx-ui-loader fgsSize="75" [fgsType]="SPINNER_TYPES.wanderingCubes"></ngx-ui-loader>

Or you can override the default configuration via forRoot() method.

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

import { AppComponent } from './app.component';

import { NgxUiLoaderModule, NgxUiLoaderConfig, SPINNER_TYPES, NGX_POSITIONS, PB_DIRECTIONS } from 'ngx-ui-loader';

const ngxUiLoaderConfig: NgxUiLoaderConfig = {
  bgsColor: 'red',
  bgsPosition: NGX_POSITIONS.bottomCenter,
  bgsSize: 40,
  bgsType: SPINNER_TYPES.rectangleBounce,
  pbDirection: PB_DIRECTIONS.leftToRight, // progress bar direction
  pbThickness: 5, // progress bar thickness
};

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    // Import NgxUiLoaderModule with custom configuration globally
    NgxUiLoaderModule.forRoot(ngxUiLoaderConfig)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Input Options

AttributeTypeRequiredDefaultDescription
bgsColorstringoptional#00ACC1Background spinner color
bgsOpacitynumberoptional0.5Background spinner opacity
bgsPositionstringoptionalbottom-rightBackground spinner postion. All available positions can be accessed via NGX_POSITIONS
bgsSizenumberoptional60Background spinner size.
bgsTypestringoptionalrectangle-bounceBackground spinner type. All available types can be accessed via SPINNER_TYPES
fgsColorstringoptional#00ACC1Foreground spinner color
fgsPositionstringoptionalcenter-centerForeground spinner position. All available positions can be accessed via NGX_POSITIONS
fgsSizenumberoptional60Foreground spinner size.
fgsTypestringoptionalrectangle-bounceForeground spinner type. All available types can be accessed via SPINNER_TYPES
logoPositionstringoptionalcenter-centerLogo position. All available positions can be accessed via NGX_POSITIONS
logoSizenumberoptional120Logo size (px)
logoUrlstringoptional(empty string)Logo url
pbColorstringoptional#00ACC1Progress bar color
pbDirectionstringoptionalltrProgress bar direction. All directions type can be accessed via PB_DIRECTIONS
pbThicknessnumberoptional5Progress bar thickness
textstringoptional(empty string)Loading text
textColorstringoptional#FFFFFFLoading text color
textPositionstringoptionalcenter-centerLoading text position. All available positions can be accessed via NGX_POSITIONS
gapnumberoptional24The gap between logo, foreground spinner and text when their positions are center-center
overlayColorstringoptionalrgba(40,40,40,.8)Overlay background color
thresholdnumberoptional500The time a loader must be showed at least before it can be stopped. It must be >= 1 millisecond. NOTE: threshold is only configured via forRoot() method.

Automatically show loader for router events

If you want the loader to start automatically for navigating between your app routes:


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

import { AppComponent } from './app.component';

import { NgxUiLoaderModule, NgxUiLoaderRouterModule } from  'ngx-ui-loader';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    NgxUiLoaderModule, // import NgxUiLoaderModule
    NgxUiLoaderRouterModule, // import NgxUiLoaderRouterModule. By default, it will show foreground loader.
    // If you need to show background spinner, do as follow:
    // NgxUiLoaderRouterModule.forRoot({ showForeground: false })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Automatically show loader for Http requests

If you want the loader to start automatically for http requests:


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

import { AppComponent } from './app.component';

import { NgxUiLoaderModule, NgxUiLoaderHttpModule } from  'ngx-ui-loader';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    NgxUiLoaderModule, // import NgxUiLoaderModule
    NgxUiLoaderHttpModule, // import NgxUiLoaderHttpModule. By default, it will show background loader.
    // If you need to show foreground spinner, do as follow:
    // NgxUiLoaderHttpModule.forRoot({ showForeground: true })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

If you wish to not show loader for some specific API urls, you can pass an array of these urls (case-insensitive) to forRoot() method as below:

NgxUiLoaderHttpModule.forRoot({ exclude: ['/api/not/show/loader', '/api/logout'] });

or if you don't want to show loader for urls which start with /api/auth, do as follow:

NgxUiLoaderHttpModule.forRoot({ exclude: ['/api/auth'] });

NOTE: And in you root app template, do not forget to include ngx-ui-loader component:

<ngx-ui-loader></ngx-ui-loader>

Changelog

v.1.1.8

  • Http interceptor - Can configure to not show loader for some API urls.
  • Npm packages - version bump.

v.1.1.5

  • Be able to show loader automatically for http requests - Http interceptor

v.1.1.2

  • Add more spinner types (total 22 spinners)
  • BugFix: Background spinner (if active) should be showed after the foreground spinner is closed out.

v.1.1.1

  • Bugs fixed

v.1.1.0

  • Show loader automatically when navigating between app routes
  • Add more spinner types
  • Be able to set a threshold
  • BugFix: Set z-index of background spinner to 99997

v.1.0.2

  • Update example app and README

v.1.0.1

  • BugFix: Position of background spinner is not fixed when scrolling
  • BugFix: Unsafe Base64 logo url
  • BugFix: Logo, foreground spinner and loading text are centered correctly and can set the gap between them via gap input

v.1.0.0

  • Show foreground loader with progress bar
  • Show background loader with different id for different tasks
  • There are 12 spinner types available
  • Be able to add logo, loading text
  • Be able to change position of spinners, logo and loading text
  • Be able to change color and size of spinners and progress bar
  • Be able to change the direction of progress bar

Credits

License

MIT © t-ho

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 01 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc