I am facing a challenge in my main module where I need to create a service that can parse a json file and store its contents in an array. The intention is to make this array easily accessible by all controllers. However, the issue arises because the function runs before the completion of the $http request, causing it to always return 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;
}
};
});