โณ ngx-spinner-loading

July 1, 2025 ยท View on GitHub

A lightweight, customizable Angular loading spinner package that supports global, section-based, inline loaders, and automatic HTTP integration via interceptors. Built with Angular standalone components and signal-based state.

๐Ÿš€ Features

  • โœ… Fullscreen, section-based, and inline loading modes
  • โœ… Auto show/hide during HTTP requests via Angular interceptor
  • โœ… Manual loader control using NgxSpinnerLoadingService
  • โœ… Customizable: size, color, animation type, speed, timeout
  • โœ… Use your own templates (type="custom")
  • โœ… Lightweight, fast, no external dependencies
  • โœ… Compatible with Angular 15+ standalone APIs

๐Ÿ“ฆ Installation

npm install ngx-spinner-loading

๐Ÿงฉ Usage

1. Import Loader in Your App

import { NgxSpinnerLoadingInterceptor } from 'ngx-spinner-loading';

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(withInterceptors([NgxSpinnerLoadingInterceptor]))
  ]
});

2. Add Global Loader in Template

<ngx-spinner-loader
  type="spinner"
  size="md"
  color="#3498db"
  mode="fullscreen"
  [timeout]="5000"
></ngx-spinner-loader>
import { Component } from '@angular/core';
import { NgxSpinnerLoaderComponent } from 'ngx-spinner-loading';

@Component({
  selector: 'app-root',
  imports: [NgxSpinnerLoaderComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent { }

โš™๏ธ Inputs โ€“ Customization

InputTypeDefaultDescription
type'spinner' | 'bar' | 'dots' | 'circle' | 'custom''spinner'Loader animation type
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Preset sizes for loader
colorstring#3498dbLoader color (hex or CSS value)
mode'fullscreen' | 'section' | 'inline''fullscreen'Loader positioning
timeoutnumberundefinedAuto-hide loader after milliseconds
speednumber1Animation speed multiplier
manualbooleanfalseIf true, always visible unless hidden manually
zIndexnumber9999z-index control for layering
template<ng-template>undefinedProvide custom loader when type="custom"

๐Ÿงช Example (Manual Control)

<ngx-spinner-loader [manual]="true" type="bar" color="green"></ngx-spinner-loader>
import { Component } from '@angular/core';
import { NgxSpinnerLoaderComponent, NgxSpinnerLoadingService } from 'ngx-spinner-loading';

@Component({
  selector: 'app-root',
  imports: [NgxSpinnerLoaderComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent { 
  constructor(private loading: NgxSpinnerLoadingService) {}

  startLoad() {
    this.loading.show();
    setTimeout(() => this.loading.hide(), 3000);
  }
}

๐Ÿ” Auto HTTP Loading

Use the provided HTTP interceptor to automatically show/hide loader for all requests:

import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { NgxSpinnerLoadingInterceptor } from 'ngx-spinner-loading';

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(withInterceptors([NgxSpinnerLoadingInterceptor]))
  ]
});

๐Ÿงฉ Section Loader Directive (Optional)

<div *ngxSpinnerLoading="isLoading">Dashboard Content...</div>
 private isLoading:boolean=false;

constructor(private loading: NgxSpinnerLoadingService) {}

loadData() {
  this.isLoading = true;
  this.http.get(...).subscribe(() => this.isLoading = false);
}

๐Ÿ’ก Custom Template Example

<ngx-spinner-loader type="custom">
  <ng-template>
    <div class="my-loader">โณ Please wait...</div>
  </ng-template>
</ngx-spinner-loader>

๐Ÿ“„ License

MIT ยฉ 2025 Thalsi