Angular 2 Http – How to Get JSON Data from API with finance_charts_json_callback() callback

后端 未结 1 1502
感动是毒
感动是毒 2021-01-20 01:12

I\'m trying to get json data from this api: http://chartapi.finance.yahoo.com/instrument/1.0/NFLX/chartdata;type=quote;range=1d/json And I don\'t know how to get into the re

1条回答
  •  野的像风
    2021-01-20 01:56

    You need to use JSONP in this case with callback name JSONP_CALLBACK:

    loadData() {
        this.jsonp.get(this.url)
            .map(res => res.json())
            .subscribe(data => console.log(data));
    }
    

    Where url should be 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 to bootstrap the app with bootstrap(App, [JSONP_PROVIDERS]) and import Jsonp service from angular2/http module.

    0 讨论(0)
提交回复
热议问题