Last active
November 24, 2019 03:56
-
-
Save kylelix7/26f2a8d2a51f72d657060a240ab040ba to your computer and use it in GitHub Desktop.
updated_service.ts
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): void { | |
| const url = `https://looc4watn6.execute-api.us-west-2.amazonaws.com/prod/price?ticker=${selected}`; | |
| this.http.get<any>(url, {}) | |
| .pipe( | |
| catchError((e) => this.handleError(e)) | |
| ).subscribe((response)=> { | |
| console.log("calling historicalData.next "); | |
| this.historicalData.next(response as (HistoricalData[])); | |
| }); | |
| } | |
| 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