Created
November 24, 2019 03:55
-
-
Save kylelix7/cac3d5fc793322b7c060ba74ade1ed78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { HistoricalData } from './models'; | |
| import { throwError, Subject } from 'rxjs'; | |
| import { catchError } from 'rxjs/operators' | |
| import { HttpClient, HttpErrorResponse } from '@angular/common/http'; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class StockDataService { | |
| public historicalData: Subject<HistoricalData[]> = new Subject(); | |
| public selectedSubject : Subject<string> = new Subject(); | |
| constructor(private http: HttpClient) { } | |
| getStaticData(selected: string, callback): void { | |
| const url = `https://<your_api_gateway_for_lambda>/prod/price?ticker=${selected}`; // use your own endpoint | |
| this.http.get<any>(url, {}) | |
| .pipe( | |
| catchError((e) => this.handleError(e)) | |
| ).subscribe((response)=> { | |
| console.log("calling historicalData.next "); | |
| this.historicalData.next(response as (HistoricalData[])); | |
| callback(); | |
| }); | |
| } | |
| private handleError(error: HttpErrorResponse) { | |
| console.log('error', error); | |
| // return an observable with a user-facing error message | |
| return throwError( | |
| 'Internal Error.'); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment