我使用有角的js asp.net web服務,返回的客戶名單 $ HTTP GET成功,但數據沒有顯示時,我重複它的HTML下面數據未顯示
<div ng-app="crudModule" ng-controller="CRUD_OperController" name="myForm" novalidate class="my-form">
<ol data-ng-repeat="cus in Customers">
<li>{{ cus.CustomerId }} ,{{ cus.CustomerName }},{{ cus.CustomerAddress }}
</ol>
</div>
是否存在任何綁定問題?
我的腳本如下
<script type="text/javascript">
var app = angular.module('crudModule', []);
app.service('studentService', function ($http) {
this.getAllCustomers = function() {
var response = $http.get("CustomerService.asmx/GetCustomers");
return response;
};
});
app.controller('CRUD_OperController', function ($scope, studentService) {
$scope.Customers = [];
loadData();
function loadData() {
var promiseGet = studentService.getAllCustomers();
promiseGet.then(
function (pl) {
$scope.Customers = pl.data;
},
function (errorPl) {
$log.error('Some Error in Getting Records.', errorPl);
}
);
}
});
</script>
當寫console.info(pl.data);數據來自如下
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCustomers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Customers>
<CustomerId>1</CustomerId>
<CustomerName>Hamid</CustomerName>
<CustomerAddress>Dhaka</CustomerAddress>
</Customers>
<Customers>
<CustomerId>2</CustomerId>
<CustomerName>Milon</CustomerName>
<CustomerAddress>Dhaka</CustomerAddress>
</Customers>
<Customers>
<CustomerId>3</CustomerId>
<CustomerName>Jakir</CustomerName>
<CustomerAddress>Dhaka</CustomerAddress>
</Customers>
<Customers>
<CustomerId>4</CustomerId>
<CustomerName>Hamid</CustomerName>
<CustomerAddress>Khulna</CustomerAddress>
</Customers>
</ArrayOfCustomers>
請共享'在後$ scope.Customers'陣列的對象。 – Saad
嘗試'return response.data'而不是'response'。 – Harish