ngx-spinner-loading
Version:
A lightweight Angular loading spinner package with full customization and HTTP interceptor support.
143 lines (111 loc) โข 4.88 kB
Markdown
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.
- โ
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
```bash
npm install ngx-spinner-loading
```
## ๐งฉ Usage
### 1. Import Loader in Your App
```ts
import { NgxSpinnerLoadingInterceptor } from 'ngx-spinner-loading';
bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(withInterceptors([NgxSpinnerLoadingInterceptor]))
]
});
```
```html
<ngx-spinner-loader
type="spinner"
size="md"
color="#3498db"
mode="fullscreen"
[]="5000"
></ngx-spinner-loader>
```
```ts
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 { }
```
| Input | Type | Default | Description |
|------------|--------------------------------------------------------|----------------|------------------------------------------------------|
| `type` | `'spinner' \| 'bar' \| 'dots' \| 'circle' \| 'custom'` | `'spinner'` | Loader animation type |
| `size` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Preset sizes for loader |
| `color` | `string` | `
| `mode` | `'fullscreen' \| 'section' \| 'inline'` | `'fullscreen'` | Loader positioning |
| `timeout` | `number` | `undefined` | Auto-hide loader after milliseconds |
| `speed` | `number` | `1` | Animation speed multiplier |
| `manual` | `boolean` | `false` | If true, always visible unless hidden manually |
| `zIndex` | `number` | `9999` | z-index control for layering |
| `template` | `<ng-template>` | `undefined` | Provide custom loader when `type="custom"` |
```html
<ngx-spinner-loader [manual]="true" type="bar" color="green"></ngx-spinner-loader>
```
```ts
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);
}
}
```
Use the provided HTTP interceptor to automatically show/hide loader for all requests:
```ts
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { NgxSpinnerLoadingInterceptor } from 'ngx-spinner-loading';
bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(withInterceptors([NgxSpinnerLoadingInterceptor]))
]
});
```
```html
<div *ngxSpinnerLoading="isLoading">Dashboard Content...</div>
```
```ts
private isLoading:boolean=false;
constructor(private loading: NgxSpinnerLoadingService) {}
loadData() {
this.isLoading = true;
this.http.get(...).subscribe(() => this.isLoading = false);
}
```
```html
<ngx-spinner-loader type="custom">
<ng-template>
<div class="my-loader">โณ Please wait...</div>
</ng-template>
</ngx-spinner-loader>
```
[](https://github.com/thalsi/ngx-spinner-loading/blob/master/LICENSE)