Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 仅显示第一项的角度ng重复_Asp.net Mvc_Angularjs_Api - Fatal编程技术网

Asp.net mvc 仅显示第一项的角度ng重复

Asp.net mvc 仅显示第一项的角度ng重复,asp.net-mvc,angularjs,api,Asp.net Mvc,Angularjs,Api,我有下表: <div data-ng-app="myApp"> <div data-ng-controller="MyCtrl"> <form> <table> <tr> <td><b>ID</b></td> <td>&

我有下表:

<div data-ng-app="myApp">
    <div data-ng-controller="MyCtrl">
        <form>
            <table>
                <tr>
                    <td><b>ID</b></td>
                    <td><b>Name</b></td>
                    <td><b>Surname</b></td>
                    <td><b>House</b></td>
                    <td><b>Address</b></td>
                    <td><b>Locality</b></td>
                    <td><b>Contact1</b></td>
                    <td><b>Contact2</b></td>
                    <td><b>Contact3</b></td>
                    <td><b>Reply</b></td>
                </tr>
                <tr><td></td></tr>
                <tr ng-repeat="telesale in telesales">
                    <td>{{telesale.ID}}</td>
                    <td>{{telesale.Name}}</td>
                    <td>{{telesale.Surname}}</td>
                    <td>{{telesale.House}}</td>
                    <td>{{telesale.Address}}</td>
                    <td>{{telesale.Locality}}</td>
                    <td>{{telesale.Contact1}}</td>
                    <td>{{telesale.Contact2}}</td>
                    <td>{{telesale.Contact3}}</td>
                    <td>{{telesale.Reply}}</td>
                </tr>
            </table>
        </form>
    </div>
  </div>
角度:

 <script type="text/javascript">
      var myApp = angular.module('myApp', []);

      myApp.controller('MyCtrl',['$scope', '$http', function ($scope, $http) {

          GetPersons();

          function GetPersons() {
            $http({
                method: 'GET',
                url: '/api/data'
            }).
            success(function (data) {
                if(data != null || data != 'undefined') {
                    $scope.telesales = data;
            }
          })
          .error(function (error) {
             $window.alert("Unable to retrieve people" + error.message);
          });
          }

      } ]);
  </script>

从api检索的数据是一个列表,其中有40行的计数作为断点进行验证,但是仅显示列表中的行。为什么会发生这种情况?

当您的webapi控制器返回HttpResponseMessage消息而不是纯数据时,可能会发生这种情况,在这种情况下,要获取数据,您必须使用result.data ie:


你应该写一些代码的描述。我们怎么能理解呢?@ebramtharwat谢谢你的反馈,当时很忙,但现在我已经更新了我的答案。@sylvester api返回一个IEnumerable列表。我按照你的建议试过了,但是什么都没有displayed@rikket请参阅此处添加console.log并让我知道您在console@slywester其他行正在显示,但行中的为空。我不明白为什么控制器中有悬挂功能。为什么不创建$scope.GetPersons,然后在结束$scope.GetPersons.之前调用它呢。。这可能就是阻止您实现所需输出的原因??
 <script type="text/javascript">
      var myApp = angular.module('myApp', []);

      myApp.controller('MyCtrl',['$scope', '$http', function ($scope, $http) {

          GetPersons();

          function GetPersons() {
            $http({
                method: 'GET',
                url: '/api/data'
            }).
            success(function (result) {
                if(result.data != null || result.data != 'undefined') {
                    $scope.telesales = result.data;
            }
          })
          .error(function (error) {
             $window.alert("Unable to retrieve people" + error.message);
          });
          }

      } ]);
  </script>