@@ -186,7 +186,7 @@ Right now, the `InvoiceController` contains all logic of our example. When the a
186
186
is a good practice to move view-independent logic from the controller into a
187
187
<a name="service">{@link services service}</a>, so it can be reused by other parts
188
188
of 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.
190
190
191
191
Let's refactor our example and move the currency conversion into a service in another file:
192
192
@@ -300,7 +300,7 @@ to something shorter like `a`.
300
300
301
301
## Accessing the backend
302
302
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.
304
304
The following example shows how this is done with AngularJS:
305
305
306
306
<example name="guide-concepts-3" ng-app-included="true">
@@ -323,10 +323,6 @@ The following example shows how this is done with AngularJS:
323
323
<file name="finance3.js">
324
324
angular.module('finance3', [])
325
325
.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';
330
326
var currencies = ['USD', 'EUR', 'CNY'];
331
327
var usdToForeignRates = {};
332
328
@@ -335,15 +331,10 @@ The following example shows how this is done with AngularJS:
335
331
};
336
332
337
333
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(",");
340
335
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;
347
338
});
348
339
};
349
340
0 commit comments