I am using angularJS to build a factory that accesses a http resource. I can see the data being returned locally near the request but the data is not returned in the controller. Here is my factory:
myNameSpace.factory('simpleFactory', function ($http) {
var factory = {};
var customers = [];
factory.getCustomers = function () {
$http.jsonp('http://URL&callback=JSON_CALLBACK').success(function (data) {
customers = data;
return customers;
})
}
return factory;
});
My controller is:
myNameSpace.controller('DetailsController', function ($scope, $http, simpleFactory) {
var cust = simpleFactory.getCustomers();
$scope.CustomerData = simpleFactory.getCustomers();
console.log(cust); //The value that is display here is undefined
});
consolestatement fires while that call is still in progress - search on returning from an async call in an Angular factory