Reputation: 3
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.
Upvotes: 0
Views: 40
Reputation: 171679
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);
})
Upvotes: 4