In Angular I've made a service to retrieve data with a $http.get call from a json file (in my code: file4.json). In the success call the data is passed into the array 'bmlService.items'. The console.log shows things went well. However, this array is empty outside the $http.get function. How can I pass the data outside this function?
This is my code:
app.service('bmlService', function($http){
var bmlService = {};
bmlService.items = [];
$http.get("file4.json")
.success(function(data){
bmlService.items = data;
console.log("inside succes call: ", bmlService.items);
})
.error(function(data, status){
alert("Something went wrong...");
});
console.log("outside http.get: ", bmlService.items);
return bmlService;
});