In my main module I want to create a service that parses a json file and pushes the contents to an array, after I would like service to have the array be returned so it is easily accessible by any of the controllers. The issue is the function is running before the $http request is complete so it always returns an empty array
dashModule.factory('dataFetch', function($http) {
var emailArray = [];
$http.get('../data/emails.json').success(function log(obj) {
for (var i = 0; i < obj.length; i++) {
emailArray[i] = obj[i];
}
});
return {
test: function() {
return emailArray;
}
};
});