ELBartoTn
ELBartoTn

Reputation: 137

JSON response not displaying on view with Angularjs

I am having a problem displaying a JSON response on web page using Angularjs, on DevTools i can see that the GET request work great and can grab all data, but when it comes to dislaying it on a list all i got is dots .

My controller :

 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;
            });

Using 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>

Result : enter image description here

Response JSON : enter image description here

I tried debuging with alerts, i figured out that my depenses array allways give undefined

Upvotes: 0

Views: 50

Answers (1)

charlietfl
charlietfl

Reputation: 171679

Your data is an object that has a property Depense that contains the array you want to repeat

Try:

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

OR:

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

Upvotes: 1

Related Questions