Skip to content

Instantly share code, notes, and snippets.

@superwalnut
Created July 7, 2020 07:45
Show Gist options
  • Save superwalnut/42a6c828f3ebc2dd1e3f5b0de4248051 to your computer and use it in GitHub Desktop.
Save superwalnut/42a6c828f3ebc2dd1e3f5b0de4248051 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { Observable, of, Subject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class CovidService {
private overallSubject = new Subject<any>();
private latestSubject = new Subject<any>();
constructor(private httpClient: HttpClient) {}
private get(url: string): Observable<any> {
return this.httpClient.get(`${environment.baseUrl}/${url}`, {
headers: {
'Content-Type': 'application/json',
} });
}
callOverall() {
this.get('timeline-overall.json').subscribe(x=>{
this.overallSubject.next(x);
});
}
getOverall(): Observable<any> {
return this.overallSubject.asObservable();
}
callLatest() {
this.get('timeline-latest.json').subscribe(x=>{
this.latestSubject.next(x);
});
}
getLatest(): Observable<any> {
return this.latestSubject.asObservable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment