src/app/shared/components/http-loader/http-loader.service.ts
Service HTTP Loader
Properties |
|
Methods |
add | ||||||||
add(key: string)
|
||||||||
Add key
Parameters :
Returns :
void
|
complete | ||||||||
complete(key: )
|
||||||||
Complete
Parameters :
Returns :
void
|
update |
update()
|
Update
Returns :
void
|
Private lastStatus |
lastStatus:
|
Default value : false
|
Last Status |
Public onChange |
onChange:
|
Type : EventEmitter<boolean>
|
On Change Emit |
Private requests |
requests:
|
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);
}
}
}