npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-perfect-loading

v1.0.0

Published

The loading system for Angular 13+ projects.

Downloads

20

Readme

ngx-perfect-loading

The loading system for Angular 13+ projects.

Referances

  1. Installation
  2. Getting started
  3. Library API
  4. Demo

Installation


You can Install ngx-perfect-loading via NPM, using the command below.

PLEASE NOTE: the Library was created for Angular 13 and high versions

NPM

npm install --save ngx-perfect-loading

Getting started


Import the NgxPLoadingModule in your root application module by .forRoot() static method:

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { NgxPLoadingModule } from "ngx-perfect-loading";

@NgModule({
  //...
  imports: [
    //...
    NgxPLoadingModule.forRoot(),
  ],
  //...
})
export class AppModule {}

After importing the NgxPLoadingModule in your root module, you can use the loading logic in the whole application:

After importing the module, you need to register listener for the GLOBAL Loading, by this code in your AppComponent:

import { Component, OnInit } from '@angular/core';
import { NgxPLoadingService } from 'ngx-perfect-loading';
// .................
@Component({
    //......
})
export class AppComponent {
    loading$!: Observable<boolean>;

    constructor(private _ngxPLoadingService: NgxPLoadingService) {
        this.loading$ = this._ngxPLoadingService.listen();
    }

  
    onClick() {
        // the function to turn on the loading
        this._ngxPLoadingService.on(); 
        setTimeout(() => {
            // the fucntion to turn off the loading
            this._ngxPLoadingService.off(); 
        }, 500);
    }
}

In AppComponent Template

<button (click)="onClick()">Click</button>
<div *ngIf="loading$ | async">
   you can have anything you need, gif, spinner, other loading indicator
</div>

Ok, So now we have a loading indicator that can be configured by HTML/CSS to show as you want.

Library API


Enums


NgxPLoadingType: The type of Loading Items(LOCAL or GLOBAL)

export enum NgxPLoadingType {
  GLOBAL = 'global',
  LOCAL = 'local'
}

Decorators


| @NgxPListener() | The Property decorator for loading listener by option | | | |-------------------|------------------------------|------------------------------|-------------| | Parameters | Type | Default | | | option | NgxPLoadingType \| string| NgxPLoadingType.GLOBAL| Optional| Usage Example

import { Component, OnInit } from '@angular/core';
import { NgxPLoadingService, NgxPListener } from 'ngx-perfect-loading';
// .................
@Component({
    //......
})
export class AppComponent {
    // loading$!: Observable<boolean>;
    
    // listen by decorator 
    @NgxPListener() loading$!: Observable<boolean>;
    

    constructor(private _ngxPLoadingService: NgxPLoadingService) {
        // now this line is not needed as we are doing the same by NgxPListener decorator
        // this.loading$ = this._ngxPLoadingService.listen();
    }

  
    onClick() {
        // the function to turn on the loading
        this._ngxPLoadingService.on(); 
        setTimeout(() => {
            // the fucntion to turn off the loading
            this._ngxPLoadingService.off(); 
        }, 500);
    }
}

In AppComponent Template

<button (click)="onClick()">Click</button>
<div *ngIf="loading$ | async">
   you can have anything you need, gif, spinner, other loading indicator
</div>

| @NgxPLoading() | The Method Decorator allows to add loading to the methods. The function is turning on the loading by type loading and turning it off when function execution ends. Also can work with Promises and Observables | | | |-------------------|-------------------------------------------|-------------|-----------------| | Parameters | Type | Default | | | loading | NgxPLoadingType \| string | NgxPLoadingType.GLOBAL | Optional |

Usage Example

import { Component, OnInit } from '@angular/core';
import { NgxPListener, NgxPLoading } from 'ngx-perfect-loading';
// .................
@Component({
    //......
})
export class AppComponent {
    // listen by decorator 
    @NgxPListener() loading$!: Observable<boolean>;

    constructor() { }
    
    // NgxPLoading Decorator is working with Promises and Observables
    // NOTE: For Observables NgxPLoading Decorator is turning off the loading when the Observable closes 
    @NgxPLoading()
    onClick() {
        return new Promise( (resolve, reject) => {
            setTimeout( () => {
                
                resolve();
            }, 1000)
        });
    }
}

In AppComponent Template

<button (click)="onClick()">Click</button>
<div *ngIf="loading$ | async">
   you can have anything you need, gif, spinner, other loading indicator
</div>

NgxPLoadingService Methods


|on() | turn on the loading by loading where loading can be the name or the type(GLOBAL or LOCAL ) of loading | | | |-----------|------------------------------------------------------------|---------|------------| | Parameters | Type | Default | | | loading | NgxPLoadingType \| string | NgxPLoadingType.GLOBAL |Optional | | Returns | Type | | | | Returns the unique name of the loading item, where the loading name can be provided by user by loading paramenter | string | | |


|off() | turn off the loading by loading where loading can be the name or the type(GLOBAL or LOCAL ) of loading | | | |-----------|--------------------------|------------------------------------------|-------------| | Parameters | Type | Default | | | loading | NgxPLoadingType \| string | NgxPLoadingType.GLOBAL |Optional| | Returns | Type | | | | Returns true when it found the item by loading name or type | boolean | | |


|listen() | listen the loading changes by loading where loading can be the name or the type(GLOBAL or LOCAL ) of loading | | | |-----------|--------------------------|------------------------------------------|-------------| | Parameters | Type | Default | | | loading | NgxPLoadingType \| string | NgxPLoadingType.GLOBAL | Optional| | Returns | Type | | | | Returns listener for loading, where loading can be the name or the type(GLOBAL or LOCAL ) of loading | Observable<boolean> | | |

Demo


Check out the interactive demo on StackBlitz.