【问题标题】:Inserting AngularJS values into HTML table is not working将 AngularJS 值插入 HTML 表不起作用
【发布时间】:2019-04-12 17:13:17
【问题描述】:

我通过 Node.js 向 AngularJS 发送 JSON。我在打印到控制台的控制器中成功接收到正确的数据。但是当我尝试用控制器填充 HTML 表时,它不起作用。我注意到,如果我使用相同的字段但使用“任务”而不是“任务”,它会将“状态”字段填充到表中,因为“任务”对象有一个“状态”字段,因此范围在技术上是有效的,但我使用“任务”字段没有运气。

控制器

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

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

表格

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

【问题讨论】:

  • 数据结构是什么样的?注意你调用data的对象是一个响应对象,你想要的数据在data.data
  • 我添加了一张图片来显示我从 console.log(data);.

标签: html json angularjs controller


【解决方案1】:

返回给$http.get().then的对象是一个响应对象,它有多个属性

您想要的数据在该对象的属性data

试试

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

【讨论】:

  • 这对我有用。感谢您的快速回答和帮助。
猜你喜欢
  • 2019-09-09
  • 1970-01-01
  • 2011-01-03
  • 2012-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-27
  • 2018-04-20
相关资源
最近更新 更多