You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
import { tap } from 'rxjs/operators';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class DashboardService
|
|
{
|
|
// Observables
|
|
private _data: BehaviorSubject<any>;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param {HttpClient} _httpClient
|
|
*/
|
|
constructor(
|
|
private _httpClient: HttpClient
|
|
)
|
|
{
|
|
// Set the private defaults
|
|
this._data = new BehaviorSubject(null);
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Accessors
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Getter for data
|
|
*/
|
|
get data$(): Observable<any>
|
|
{
|
|
return this._data.asObservable();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Get data
|
|
*/
|
|
getData(): Observable<any>
|
|
{
|
|
return this._httpClient.get('/api/summary').pipe(
|
|
tap((response: any) => {
|
|
this._data.next(response);
|
|
})
|
|
);
|
|
}
|
|
}
|