Skip to content

Instantly share code, notes, and snippets.

@kylelix7
Created November 24, 2019 03:55
Show Gist options
  • Select an option

  • Save kylelix7/cac3d5fc793322b7c060ba74ade1ed78 to your computer and use it in GitHub Desktop.

Select an option

Save kylelix7/cac3d5fc793322b7c060ba74ade1ed78 to your computer and use it in GitHub Desktop.
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