-
Notifications
You must be signed in to change notification settings - Fork 42
Getting started
T edited this page Feb 27, 2019
·
5 revisions
Install ngx-ui-loader
via NPM, using the command below.
$ npm install --save ngx-ui-loader
$ yarn add ngx-ui-loader
$ npm install --save ngx-ui-loader@1.2.5
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 { }
After importing the NgxUiLoaderModule
, use ngx-ui-loader
component in your root app template:
<ngx-ui-loader></ngx-ui-loader>
See Attributes of NgxUiLoaderComponent for more details about attributes.
You can skip this step if you do not want to use multiple loaders
After importing the NgxUiLoaderModule
, use ngx-ui-loader
component in your template:
<div style="position: relative"> <!-- the position of the parent container must be set to relative -->
<!-- It is really important to set loaderId for non-master loader -->
<ngx-ui-loader [loaderId]="'loader-01'"></ngx-ui-loader>
</div>
<div style="position: relative"> <!-- the position of the parent container must be set to relative -->
<!-- It is really important to set loaderId for non-master loader -->
<ngx-ui-loader [loaderId]="'loader-02'"></ngx-ui-loader>
</div>
<ngx-ui-loader></ngx-ui-loader> <!-- this is master loader and its loaderId is "master" by default -->
<!-- Note 1: If you really want to change loaderId of master loader, please use NgxUiLoaderModule.forRoot() method. -->
<!-- Note 2: Your application can only have ONE master loader.
The master loader should be placed in your app root template, so you can call it anywhere in you app. -->
See simple setup for multiple loaders here on Stackblitz.
- The application can have only one master loader and many non-master loader.
- The master loader will block the entire viewport.
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 spinner of the master loader with 'default' taskId
// Stop the foreground loading after 5s
setTimeout(() => {
this.ngxService.stop(); // stop foreground spinner of the master loader with 'default' taskId
}, 5000);
// OR
this.ngxService.startBackground('do-background-things');
// Do something here...
this.ngxService.stopBackground('do-background-things');
this.ngxService.startLoader('loader-01'); // start foreground spinner of the loader "loader-01" with 'default' taskId
// Stop the foreground loading after 5s
setTimeout(() => {
this.ngxService.stopLoader('loader-01'); // stop foreground spinner of the loader "loader-01" with 'default' taskId
}, 5000);
}
}
See API - NgxUiLoaderService for more details.
- Demo & Examples
-
Getting Started
2.1 Install
2.2 ImportNgxUiLoaderModule
2.3 Includengx-ui-loader
component
2.4 Multiple loaders
2.5 UseNgxUiLoaderService
service - API - NgxUiLoaderService
- Attributes of NgxUiLoaderComponent
-
NgxUiLoaderBlurred directive
5.1 Usage
5.2 Attributes -
Custom Template
6.1 Usage -
Custom configuration for NgxUiLoaderModule
7.1 Usage
7.2 Parameters offorRoot()
method -
Automatically show loader for router events
8.1 Usage
8.2 Parameters offorRoot()
method -
Automatically show loader for http requests
9.1 Usage
9.2 Parameters offorRoot()
method - Changelog
- Credits
- License