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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -