2016-05-22 99 views
0

我使用有角的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> 
+0

请共享'在后$ scope.Customers'阵列的对象。 – Saad

+0

尝试'return response.data'而不是'response'。 – Harish

回答

0

Live Demo为您服务。

我想推荐angular-xml来处理<xml>角度响应。

更多详细信息在angular-xml和依赖x2js

  1. 包括x2jsangular-xml到您的项目。

  2. xml模块注入您的应用程序并配置httpProvider

的HTTP拦截器将所有的XML响应转换到一个JavaScript对象。

var app = angular.module('crudModule', ['xml']); 

app.config(function($httpProvider) { 
    $httpProvider.interceptors.push('xmlHttpInterceptor'); 
}); 
  • 小心你的响应数据结构。
  • 通过console.info(PL),检查结果对象的从XML解析的嵌套结构

    function loadData() { 
        var promiseGet = studentService.getAllCustomers(); 
        promiseGet.then(
         function(pl) { 
         console.info(pl); 
         $scope.Customers = pl.data.ArrayOfCustomers.Customers; 
         }, 
         function(errorPl) { 
         $log.error('Some Error in Getting Records.', errorPl); 
         } 
        ); 
        } 
    
    +0

    我已收到控制器中的数据,但无法将其显示到html视图 – Belayet

    +0

    '$ scope.Customers = pl.data;'后,你会'console.info(pl.data);'并在这里显示数据? –

    +0

    是的,它显示数据为arrayofCustomers – Belayet