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-block-loading

v0.4.0

Published

A spinner for Angular that will appear when HTTP requests are running.

Downloads

100

Readme

ngx-block-loading

A loading spinner for Angular applications that appears when HTTP requests are running, and optionally when elements are rendering.

npm version

Table of contents

Demo

For a demo, download the repository, then run the following commands

npm run start:api
npm run watch:lib
npm start

The first command will start a fake API that is used to test the rendering part of the library, the second will compile ngx-block-loading, the third command will open a demo site that shows this working.

Demo

Installation

Install ngx-block-loading via NPM, using the command below.

NPM

npm install --save ngx-block-loading

Getting started

Import the NgxBlockLoadingModule in your root application module:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxBlockLoadingModule } from 'ngx-block-loading';

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

You must mark a HTML element as being an element that will have a block loading element displayed over the top of it.

<table ngxBlockLoading #loading="ngxBlockLoading"></table>

This will create a new element within this marked HTML element that will display a loading gif. This can be customised using CSS classes. See Customisation.

In order to use this element you need to have it as a ViewChild in your backing component. In order to do this you need to use the exported as value of ngxBlockLoading, eg #loading="ngxBlockLoading".

@ViewChild('loading')
loadingDirective: NgxBlockLoadingDirective;

You then need to tell the request that you are making which NgxBlockLoadingDirectives you want to use when running it.

@ViewChild('loading')
loadingDirective: NgxBlockLoadingDirective;

...

this.http.get('https://test.com').pipe(ngxBlockLoading({ blocking: this.loadingDirective }));

Where the value of block can be either a single instance of NgxBlockLoadingDirective or an array of them.

Full Page Blocking

If you want to block the whole page when loading in a certain case you need to have the full page loading component added.

<ngx-block-loading-full-page></ngx-block-loading-full-page>

You also need to mark the HTTP request as being a full page loading request.

this.http.get('https://test.com').pipe(ngxBlockLoading({ fullPage: true }));

Rendering

You can also keep the loading gif on top of the element until a certain amount of rendering is done. This is done by putting a directive against the element that is doing the rendering and passing false when finished. The most common usage for this is ngFor after running a HTTP request.

<tr *ngFor="let result of results; let isLast = last" [ngxBlockRendering]="!isLast">

Unless specified otherwise this will start as soon as the directive is added to the DOM. This functionality can be switched off via the startOnInit input.

If you do not want it to start on init then you will need to tell it when to start using the forceStart input.

This will mark the parent element as being the container for the loading, this is to facilitate the main usage of this being for ngFor. The first item in the list will trigger the loading gif to appear, the last element being rendered will cause the loading gif to disappear.

Working with existing Loading Directive

If you are using this rendering directive it will most likely conflict with any loading directives - the loading directive will stop and the rendering directive will start with a gap. In order to resolve this we can tell the rendering directive that it is using a loading directive.

<table ngxBlockLoading #loading="ngxBlockLoading">

...

<tr *ngFor="let result of results; let isLast = last" [ngxBlockRendering]="!isLast" [loadingDirective]="loading>

Customisation

There are multiple levels at which you can customise.

  1. Module import level
  2. Element level
  3. Full page element level

Most of the options across these levels are the same, so he options are just marked with what is available at each level.

Input parameters

| Input | Default | Module | Element | Full Page | Details | | --------------------- | ---------------------------- | ------------------ | ------------------ | ------------------ | --------------------------------------------------------------------------------------------------------------- | | inTime | 0.25s | :heavy_check_mark: | :heavy_check_mark: | :x: | The length of time to animate the element that is block loading is shrunk to the specified height. | | outTime | 0.25s | :heavy_check_mark: | :heavy_check_mark: | :x: | The length of time to animate the element back to its normal size. | | loaderOutTime | 0.25s | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | The length of time to take in removing the loading gif. | | containerHeight | 100px | :heavy_check_mark: | :heavy_check_mark: | :x: | The height to take with the blocking loading gif. | | loadingContainerClass | ngx-block-loading--container | :heavy_check_mark: | :heavy_check_mark: | :x: | The CSS class to put on the container for the block loading gif. | | loadingClass | ngx-block-loading | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | The CSS class to put on the loading element itself. | | loadingFullPageClass | ngx-block-loading__full-page | :heavy_check_mark: | :x: | :heavy_check_mark: | The extra class that goes on the full page version of the loading element itself. | | template | | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | The Angular template inserted instead of the normal loading element with the defined classes. | | ngxBlockLoading | | :x: | :heavy_check_mark: | :x: | Override whether or not to display the loading element. If this is specified running HTTP requests are ignored. | | isLoading | | :x: | :x: | :heavy_check_mark: | Override whether or not to display the loading element. If this is specified running HTTP requests are ignored. |

Styles

In order to use the default styles you want to add the following to your regular scss file.

@import 'ngx-block-loading/assets/ngx-block-loading.scss';