0

I am sending JSON to AngularJS through Node. I receive the correct data successfully in the controller which I print to the console. But when I try to fill the HTML table with the controller it doesn't work. I noticed that if I use the same fields but with "tasks" instead of "task" it will fill the "status" field into the table since the "tasks" object has a "status" field so the scope is technically working but I have no luck using "task" fields.

Controller

projectApp_TaskList.controller('getTaskListController', function ($scope, $http) {

    $http.get('/getTaskList')
        .then(function (data) {
            $scope.tasks = data;
            console.log($scope.tasks);
        });
});

Table

    <div>
        <table>
            <thead>
                <tr>
                    <td>Priotity</td>
                    <td>Status</td>
                    <td>Title</td>
                    <td>Limit Date</td>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="task in tasks">
                    <td>{{task.priority}}</td>
                    <td>{{task.status}}</td>
                    <td>{{task.title}}</td>
                    <td>{{task.limitDate}}</td>
                </tr>
            </tbody>
        </table>
    </div>

Here's the link to the data I get on the console.

2
  • What does data structure look like? Note the object you call data is a response object and the data you want is in data.data Commented Apr 12, 2019 at 17:18
  • I have added an image to show what I get from the console.log(data);. Commented Apr 12, 2019 at 17:22

1 Answer 1

4

The object returned to $http.get().then is a response object that has multiple properties

The data you want is in a property data of that object

Try

$http.get('/getTaskList')
    .then(function (response) {
        $scope.tasks = response.data;
        console.log($scope.tasks);
    })
Sign up to request clarification or add additional context in comments.

1 Comment

That worked for me. Thanks for the quick answer and help.

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.