I am currently working with AngularJS and have successfully retrieved exchange rates from fixer.io. However, I am facing difficulties in extracting both the country and rate data by looping through the key-value pairs. At the moment, I can only access the rate and I also need the country information. Can anyone pinpoint what I may be missing in my code? Below is a snippet showcasing how the rates are displayed on the fixer.io website.
HTML5
<div ng-controller="AngularJSCtrl">
<ul ng-repeat="x in data.rates">
<li>{{ x }}</li>
</ul>
</div>
JS
var myApp = angular.module('myApp',[]);
myApp.service('dataService', function($http) {
delete $http.defaults.headers.common['X-Requested-With'];
this.getData = function(callbackFunc) {
$http({
method: 'GET',
url: 'http://api.fixer.io/latest',
params: 'limit=10, sort_by=created:desc',
headers: {'Authorization': 'Token token=xxxxYYYYZzzz'}
}).success(function(data){
// With the data succesfully returned, call our callback
callbackFunc(data);
}).error(function(){
alert("error");
});
}
});
myApp.controller('AngularJSCtrl', function($scope, dataService) {
$scope.data = null;
dataService.getData(function(dataResponse) {
$scope.data = dataResponse;
});
});
Rates as displayed on the website
{
"base": "EUR",
"date": "2016-09-20",
"rates": {
"AUD": 1.4812,
"BGN": 1.9558,
"BRL": 3.6473,
"CAD": 1.4792,
"CHF": 1.0943,
"CNY": 7.4604,
"CZK": 27.022,
"DKK": 7.452,
"GBP": 0.86213,
"HKD": 8.6753,
"HRK": 7.5127,
"HUF": 309.12,
"IDR": 14698.01,
"ILS": 4.2231,
"INR": 74.962,
"JPY": 113.93,
"KRW": 1252.4,
"MXN": 21.965,
"MYR": 4.631,
"NOK": 9.2648,
"NZD": 1.522,
"PHP": 53.527,
"PLN": 4.2975,
"RON": 4.4513,
"RUB": 72.5141,
"SEK": 9.5763,
"SGD": 1.5237,
"THB": 38.909,
"TRY": 3.3275,
"USD": 1.1184,
"ZAR": 15.5144
}
}