typescript - Angular 2 Http – How to Get JSON Data from API with finance_charts_json_callback() callback -
i'm trying json data api: http://chartapi.finance.yahoo.com/instrument/1.0/nflx/chartdata;type=quote;range=1d/json , don't know how returned finance_charts_json_callback().
i'm using angular 2's http.get():
loaddata() { return this.http .get(this.url) .map((res) => res.json()) .subscribe((data) => console.log(data)); }
when gets => res.json()
, throws error:
exception: syntaxerror: unexpected token i
you need use jsonp in case callback name jsonp_callback:
loaddata() { this.jsonp.get(this.url) .map(res => res.json()) .subscribe(data => console.log(data)); }
where url
should http://chartapi.finance.yahoo.com/instrument/1.0/nflx/chartdata;type=quote;range=1d/json/?callback=jsonp_callback
, note callback=jsonp_callback
part.
and of course, remember bootstrap app bootstrap(app, [jsonp_providers])
, import jsonp
service angular2/http
module.
Comments
Post a Comment