File

src/app/manage-learn/core/services/loader/loader.service.ts

Index

Properties
Methods

Constructor

constructor(loadingController: LoadingController)
Parameters :
Name Type Optional
loadingController LoadingController No

Methods

Async startLoader
startLoader(message?)
Parameters :
Name Optional
message Yes
Returns : any
Async stopLoader
stopLoader()
Returns : any

Properties

isLoading
Type : boolean
Default value : false
loaderCounter
Type : number
Default value : 0
loaderRef
Type : any
loading
Type : HTMLIonLoadingElement
import { Injectable } from '@angular/core';
import { LoadingController } from '@ionic/angular';

@Injectable({
  providedIn: 'root',
})
export class LoaderService {
  loaderRef: any;
  isLoading: boolean = false;
  loaderCounter = 0;
  loading: HTMLIonLoadingElement;

  constructor(private loadingController: LoadingController) {}

  async startLoader(message?) {
    if (this.loaderCounter < 0) {
      this.loaderCounter=0
    }
    this.loaderCounter = this.loaderCounter + 1;

    if (this.loaderCounter === 1) {
      this.isLoading = true;
      this.loading = await this.loadingController.create({
        cssClass: 'custom-loader-message-class',
        spinner: 'circular',
        message: message ? message : 'Please wait while loading ...',
        translucent: true,
        backdropDismiss: false,
      });
      await this.loading.present();
    }
  }

  async stopLoader() {
    this.loaderCounter = this.loaderCounter - 1;
    if (this.loaderCounter === 0) {
      this.isLoading = false;
      await this.loading.dismiss();
    }
  }
}

results matching ""

    No results matching ""