我正在使用 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
});