File

src/app/shared/components/http-loader/http-loader.service.ts

Description

Service HTTP Loader

Index

Properties
Methods

Methods

add
add(key: string)

Add key

Parameters :
Name Type Optional Description
key string
Returns : void
complete
complete(key: )

Complete

Parameters :
Name Type Optional Description
key
Returns : void
update
update()

Update

Returns : void

Properties

Private lastStatus
lastStatus:
Default value : false

Last Status

Public onChange
onChange: EventEmitter<boolean>
Type : EventEmitter<boolean>

On Change Emit

Private requests
requests: Array<any>
Type : Array<any>

Request Array

import { EventEmitter, Injectable } from '@angular/core';

/**
 * Service HTTP Loader
 */
@Injectable()
export class HttpLoaderService {

  /**
   * Request Array
   */
  private requests: Array<any> = [];

  /**
   * Last Status
   */
  private lastStatus = false;

  /**
   * On Change Emit
   */
  public onChange: EventEmitter<boolean> = new EventEmitter();

  /**
   * Add key
   * @param key
   */
  add(key: string) {
    this.requests.push(key);
    this.update();
  }

  /**
   * Complete
   * @param key
   */
  complete(key) {
    this.requests = this.requests.filter(request => request !== key);
    this.update();
  }

  /**
   * Update
   */
  update() {
    const status = this.requests.length > 0;
    if (status !== this.lastStatus) {
      this.lastStatus = status;
      this.onChange.emit(status);
    }
  }

}

results matching ""

    No results matching ""