【问题标题】:JSON response not displaying on view with AngularjsJSON响应没有显示在Angularjs的视图中
【发布时间】:2018-04-02 10:22:45
【问题描述】:

我在使用 Angularjs 在网页上显示 JSON 响应时遇到问题,在 DevTools 上我可以看到 GET 请求工作得很好并且可以获取所有数据,但是当我将它显示在列表上时,我得到的只是点.

我的控制器:

 budgetApp.controller('DepensesListCtrl', ['$scope', '$http',
        function DepensesListCtrl($scope, $http) {
            $scope.depenses = [];

            $http.get('http://localhost:3000/api/depenses', {withCredentials: true}).success(function(data) {
                $scope.depenses = data;
            });

使用 ng-repeat :

<div >
    <div class="jumbotron text-center">
            <h1>depenses Page</h1>   
    </div>
    <ul ng-repeat="depense in depenses">
        <li>{{depense.depname}}</li>
        <li>{{depense.depcat}} </li>
    </ul>

结果:

响应 JSON :

我尝试使用警报进行调试,我发现我的 depenses 数组总是给出 undefined

【问题讨论】:

    标签: javascript angularjs json node.js


    【解决方案1】:

    您的数据是一个对象,其属性Depense 包含您要重复的数组

    试试:

    $http.get('http://localhost:3000/api/depenses', {withCredentials: true}).success(function(data) {
           $scope.depenses = data.Depense;
                               // ^^^ property that contains array
    });
    

    或者:

    <ul ng-repeat="depense in depenses.Depense">
    

    【讨论】:

      猜你喜欢
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多