Giter VIP home page Giter VIP logo

ng2-loading-indicator's Introduction

ng2-loading-indicator @decorator

npm-image downloads-image total-downloads-image

The simplest library for loading indicator @decorator in Angular 2/4.

  • No dependencies
  • Simplest

https://media.giphy.com/media/3o7buiqQhDuGYmc2go/giphy.gif

1. Install

npm install ng2-loading-indicator --save

2. Using

Add into .component

import { LoadingIndicator } from 'ng2-loading-indicator';

We have 2 ways to use this decorator in our code:

1. Whole page loading

1.1 When return a Subscription after call .subscribe

  @LoadingIndicator()
  tryLoadingIndicator() {
    return Observable.timer(3000).subscribe(x => {
      console.log('finished 3s');
    });
  }
  • Other cases in http,forms,... anything in Angular are using rxjs
  @LoadingIndicator()
  getDataFromApi() {
    return this.http.get('your-api.com')
    .map(res => res.json())
    .subscribe(res => {});
  }

1.2 In async/await function

@LoadingIndicator()
async tryLoadingIndicator() {
  await Observable.timer(3000).toPromise();
}

1.3 When return a Observable<T> after call from operators do, map,...

  @LoadingIndicator()
  tryLoadingIndicator() {
    return Observable.timer(3000).do(x => {
      console.log('finished 3s');
    });
  }

2. Parts of the page loading

// Define a variable with HTMLElement
$div: Element; 

// Using ElementRef to get DOM element for this component
constructor(private elementRef: ElementRef) {}

// Set value for above variable (HTMLElement)
ngOnInit() {
    this.$div = this.elementRef.nativeElement.querySelector('div');
}

// Add the variable string list to @decorator
@LoadingIndicator(['$div'])
async trySectionLoading() {
  await Observable.timer(3000).toPromise();
}

ng2-loading-indicator's People

Contributors

dinhduongrestaff avatar jinhduong avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.