NgxMatLoading
Customizable Loading overlay service and directive for Angular Material.
StackBlitz Demo
Features
- Global or Element/Component overlay
- Custom inner component
TODO
Installation
npm -i ngx-mat-loading
Update angular.json
"styles": [
"node_modules/ngx-mat-loading/ngx-mat-loading.css",
"src/styles.scss"
]
Import and configure
import { NgxMatLoadingModule, NGX_MAT_LOADING_DEFAULT_OPTIONS } from "ngx-mat-loading";
@NgModule({
...,
imports: [
NgxMatLoadingModule
],
providers: [
{
provide: NGX_MAT_LOADING_DEFAULT_OPTIONS,
useValue: {
backdropClass: 'ngx-mat-loading-dark-backdrop',
innerOverlay: true,
componentClass: 'my-loading-component',
componentProps: { indicator: 'bar', text: 'LOADING...' }
}
}
],
...
})
Example
Global loading
import { Component } from "@angular/core";
import { concatMap, delay, finalize, tap } from "rxjs/operators";
import { NgxMatLoadingService } from "ngx-mat-loading";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(
private _loading: NgxMatLoadingService
) {}
showLoading() {
this._loading.show({
mode: "determinate",
text: 'Starting...'
}, {
componentStyle: {
'width': '150px'
}
});
of(0, 3, 15, 34, 62, 63, 64, 65, 99, 100).pipe(
concatMap(x => of(x).pipe(delay(500))),
tap(v => this._loading.update({ value: v, text: `Processing ${v}%...` })),
finalize(() => this._loading.hide())
).subscribe();
}
}
Element/Component loading
export class MyComponent {
loading: boolean = false;
}
<div
class="my-div"
[ngxMatLoading]="loading"
ngxMatLoadingBackdropClass="ngx-mat-loading-light-backdrop"
ngxMatLoadingInnerOverlay>
content
</div>
<button (click)="loading = !loading">Toggle loading</button>
Services
NgxMatLoadingService
Properties
Property | Description |
---|
visible: boolean | |
componentRef?: ComponentRef<any> | Reference to inner loading component. |
Methods
Method | Description |
---|
show(props?: NgxMatLoadingComponentProps | any, options?: NgxMatLoadingOptions): void | Show overlay. |
update(props?: NgxMatLoadingComponentProps | any): void | Update overlay's component content. |
hide(): void | Hide overlay. |
Directives
NgxMatLoadingDirective
Selector: ngxMatLoading
Exported as: ngxMatLoading
Properties
Property | Description |
---|
@Input('ngxMatLoading') show: boolean | |
@Input('ngxMatLoadingBackdropClass') backdropClass?: string | |
@Input('ngxMatLoadingPanelClass') panelClass?: string | |
@Input('ngxMatLoadingInnerOverlay') innerOverlay: boolean | Default false. |
@Input('ngxMatLoadingComponentType') componentType?: ComponentType<any> | |
@Input('ngxMatLoadingComponentProps') componentProps?: NgxMatLoadingComponentProps | any | |
@Input('ngxMatLoadingComponentClass') componentClass?: string | |
@Input('ngxMatLoadingComponentStyle') componentStyle?: {[key:string]: string} | |
visible: boolean | |
componentRef?: ComponentRef<any> | Reference to inner loading component. |
Methods
Method | Description |
---|
show(props?: NgxMatLoadingComponentProps | any): void | Show overlay. |
update(props?: NgxMatLoadingComponentProps | any): void | Update overlay's component content. |
hide(): void | Hide overlay. |
Interfaces
NgxMatLoadingComponentProps
export interface NgxMatLoadingComponentProps {
text?: string;
value?: number;
mode?: 'indeterminate' | 'determinate';
indicator?: 'none' | 'spinner' | 'bar';
indicatorDiameter?: number;
indicatorWidth?: number;
indicatorColor?: string;
}
NgxMatLoadingOptions
export interface NgxMatLoadingOptions {
backdropClass?: string;
panelClass?: string;
innerOverlay?: boolean;
blockScroll?: boolean,
componentType?: ComponentType<any>;
componentClass?: string;
componentStyle?: {[key: string]: string};
componentProps?: NgxMatLoadingComponentProps | any;
}