Created
July 7, 2020 07:45
-
-
Save superwalnut/42a6c828f3ebc2dd1e3f5b0de4248051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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