0
這是我廠的服務,它是從Web服務AngularJS工廠服務不返回動態數據控制器
var customersFactory = function ($http) {
var customer = [];
var getCustomersURL = "http://localhost:50340/Services/CustomerService.asmx/GetCustomers";
customer.XMLtoJSON = function (data) {
data = data.replace('<?xml version="1.0" encoding="utf-8"?>', ''); ;
data = data.replace('<string xmlns="http://tempuri.org/">', '').replace('</string>', '');
return $.parseJSON(data);
};
customer.GetCustomers = function() {
$http.post(getCustomersURL).success(function (data, status, headers, config) {
return customer.XMLtoJSON(data);
}).error(function (ata, status, headers, config) { });
};
return customer;
};
app.factory('customersFactory', customersFactory);
現在獲取數據,這是被我的控制器使用
app.controller("CustomersController", function ($scope, customersFactory) {
var service = [];
service = customersFactory.GetCustomers();
$scope.Customers = service;
if ((typeof (service) != 'undefined') && service.length > 0) {
service.then(function (result) {
$scope.Customers = result;
});
}
});
的服務的價值總是未定義或爲空。數據沒有從工廠傳遞到控制器。我調用一個簡單的Web服務,沒有花哨的API或WCF。
它有一些靜態/虛擬數據,它的工作正常。控制器正在讀取數據並正在顯示。
我在哪裏做錯了?
任何幫助,非常感謝。
謝謝
非常感謝WalksAway。收到。我明白我出錯的地方。非常感謝。 – Vamsi