Reasonably new to Angular. I have a service which purpose is to get information from a JSON file, iterate through each object, so I can access the data from the controller. I can access the JSON data from the $http request, but not the JSON data from the for loop within the service.
Is this is the best way to loop through items in AngularJS, if so, how do I access and display this information from the controller?
app.factory('fxRate', ['$http', '$q', function($http, $q){
var factory = {};
factory.getFx = function() {
var deferred = $q.defer();
$http.get('../json/mcfx.json')
.then(
function(response){
var d, i;
var rateData = response.data.fxrate;
for (var i in rateData) {
var fx = rateData[i].usdToEur;
var fxDate = rateData[i].date;
}
deferred.resolve(response.data);
},
function(errResponse){
deferred.reject(errResponse.data);
}
)
return deferred.promise;
}
return factory;
}]);
app.controller('dashboard', ['$scope', 'fxRate', function($scope, fxRate){
$scope.dailyFx = function() {
fxRate.getFx().then(function(data){
console.log(data)
});
}
$scope.dailyFx();
}])