@@ -186,7 +186,7 @@ Right now, the `InvoiceController` contains all logic of our example. When the a
186186is a good practice to move view-independent logic from the controller into a
187187<a name="service">{@link services service}</a>, so it can be reused by other parts
188188of the application as well. Later on, we could also change that service to load the exchange rates
189- from the web, e.g. by calling the Yahoo Finance API, without changing the controller.
189+ from the web, e.g. by calling the [Fixer.io](http://fixer.io) exchange rate API, without changing the controller.
190190
191191Let's refactor our example and move the currency conversion into a service in another file:
192192
@@ -300,7 +300,7 @@ to something shorter like `a`.
300300
301301## Accessing the backend
302302
303- Let's finish our example by fetching the exchange rates from the Yahoo Finance API.
303+ Let's finish our example by fetching the exchange rates from the [Fixer.io](http://fixer.io) exchange rate API.
304304The following example shows how this is done with AngularJS:
305305
306306<example name="guide-concepts-3" ng-app-included="true">
@@ -323,10 +323,6 @@ The following example shows how this is done with AngularJS:
323323 <file name="finance3.js">
324324 angular.module('finance3', [])
325325 .factory('currencyConverter', ['$http', function($http) {
326- var YAHOO_FINANCE_URL_PATTERN =
327- '//query.yahooapis.com/v1/public/yql?q=select * from ' +
328- 'yahoo.finance.xchange where pair in ("PAIRS")&format=json&' +
329- 'env=store://datatables.org/alltableswithkeys';
330326 var currencies = ['USD', 'EUR', 'CNY'];
331327 var usdToForeignRates = {};
332328
@@ -335,15 +331,10 @@ The following example shows how this is done with AngularJS:
335331 };
336332
337333 var refresh = function() {
338- var url = YAHOO_FINANCE_URL_PATTERN.
339- replace('PAIRS', 'USD' + currencies.join('","USD'));
334+ var url = 'https://api.fixer.io/latest?base=USD&symbols=' + currencies.join(",");
340335 return $http.get(url).then(function(response) {
341- var newUsdToForeignRates = {};
342- angular.forEach(response.data.query.results.rate, function(rate) {
343- var currency = rate.id.substring(3,6);
344- newUsdToForeignRates[currency] = window.parseFloat(rate.Rate);
345- });
346- usdToForeignRates = newUsdToForeignRates;
336+ usdToForeignRates = response.data.rates;
337+ usdToForeignRates['USD'] = 1;
347338 });
348339 };
349340
0 commit comments