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

ngx-mat-loading

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-mat-loading

Customizable Loading overlay service and directive for Angular Material.

  • 1.1.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NgxMatLoading

Customizable Loading overlay service and directive for Angular Material.

StackBlitz Demo

Features

  • Global or Element/Component overlay
  • Custom inner component

TODO

  • Tests
  • Documentation

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
PropertyDescription
visible: boolean
componentRef?: ComponentRef<any>Reference to inner loading component.
Methods
MethodDescription
show(props?: NgxMatLoadingComponentProps | any, options?: NgxMatLoadingOptions): voidShow overlay.
update(props?: NgxMatLoadingComponentProps | any): voidUpdate overlay's component content.
hide(): voidHide overlay.

Directives

NgxMatLoadingDirective

Selector: ngxMatLoading
Exported as: ngxMatLoading

Properties
PropertyDescription
@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
MethodDescription
show(props?: NgxMatLoadingComponentProps | any): voidShow overlay.
update(props?: NgxMatLoadingComponentProps | any): voidUpdate overlay's component content.
hide(): voidHide overlay.

Interfaces

NgxMatLoadingComponentProps

export interface NgxMatLoadingComponentProps {
  /**
   * Loading message
   */
  text?: string;

  /**
   * Spinner's or Bar's value. Works only with 'spinner' or 'bar' indicator with 'determinate' mode.
   */
  value?: number;

  /**
   * Spinner's or Bar's mode
   */
  mode?: 'indeterminate' | 'determinate';

  /**
   * Show progress with MatSpinner or MatProgressBar.
   */
  indicator?: 'none' | 'spinner' | 'bar';

  /**
   * Spinner's diameter
   */
  indicatorDiameter?: number;

  /**
   * Spinner's stroke width or Bar width
   */
  indicatorWidth?: number;

  /**
   * Spinner or Bar color
   */
  indicatorColor?: string;
}

NgxMatLoadingOptions

export interface NgxMatLoadingOptions {
  /**
   * Loading's overlay backdrop class
   */
  backdropClass?: string;

  /**
   * Loading's overlay content panel class
   */
  panelClass?: string;

  /**
   * Whether overlay is inside covered element or in global overlay container. Works only with NgxMatLoading directive.
   * Default false.
   */
  innerOverlay?: boolean;

  /**
   * Whether loading overlay will block global scroll. Works only with NgxMatLoading service. Default is false.
   */
  blockScroll?: boolean,

  /**
   * Loading's overlay content component. Default NgxMatLoadingComponent.
   */
  componentType?: ComponentType<any>;

  /**
   * Loading's overlay content component's CSS class.
   */
  componentClass?: string;

  /**
   * Loading's overlay content component's CSS style.
   */
  componentStyle?: {[key: string]: string};

  /**
   * Loading's overlay content component properties (inputs).
   */
  componentProps?: NgxMatLoadingComponentProps | any;
}

Keywords

FAQs

Package last updated on 18 May 2022

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