Angular Developer Guide https://docs.angularjs.org/guide/concepts
So this is the url: var YAHOO_FINANCE_URL_PATTERN =
'//query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange
where pair in
("PAIRS")&format=json&env=store://datatables.org/alltableswithkeys&callback=JSON_CALLBACK';
If you run it it will return the following (PAIRS above is USDEUR):
/**/JSON_CALLBACK({"query":{"count":1,"created":"2015-11-27T22:10:34Z","lang":"en-US","results":{"rate":{"id":"USDEUR","Name":"USD/EUR","Rate":"0.9440","Date":"11/27/2015","Time":"10:10pm","Ask":"0.9443","Bid":"0.9440"}}}});
This is the code that processes Json:
var url = YAHOO_FINANCE_URL_PATTERN.
replace('PAIRS', 'USD' + currencies.join('","USD'));
return $http.jsonp(url).then(function(response) {
var newUsdToForeignRates = {};
angular.forEach(response.data.query.results.rate, function(rate) {
var currency = rate.id.substring(3,6);
newUsdToForeignRates[currency] = window.parseFloat(rate.Rate);
});
Here is the plunker, code is in finance3.js:
http://plnkr.co/edit/m3K11e6KItx6HwfCCHCo?p=preview
I can see query, results, rate etc in the JSON file AND in the code, but
the code also has - response and data.
(1) Is the whole JSON treated as 'response' and where does data come from
(its not in JSON file)?
(2) What do you do with this piece -> /**/JSON_CALLBACK?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.