angularJS を使用して、http リソースにアクセスするファクトリを構築しています。リクエストの近くでデータがローカルに返されていることがわかりますが、コントローラーではデータが返されません。これが私の工場です:
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;
});
私のコントローラーは:
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
});