0

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

1 Answer 1

1

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">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.