【问题标题】:ng-repeat not showing any contentsng-repeat 不显示任何内容
【发布时间】:2016-12-22 00:30:22
【问题描述】:

我正在尝试使用 Mongoose 和 AngularJS 将内容放入我的 MongoDB。到目前为止,一切似乎都在工作,但是当我使用 ng-repeat 时,表格出现空白。

HTML 代码

<div class="container" ng-controller="FormController">
    <table class="table table-striped">
        <tbody>
        <tr ng-repeat="sensordata in sensordatas track by $index">
            <td>{{sensordata.topic}}</td> 
            <td>{{sensordata.message}}</td>
            <td>{{sensordata.when}}</td>
        </tr>
        </tbody>
    </table>
</div>

app.js

var app = angular.module('FormApp', []);

app.controller("FormController", function ($http, $scope){
$http.get("/api/sensordata")
    .then(function (response) {
        $scope.sensordatas = response;
    });
})

server.js

//Data Schema
var dataSchema = new mongoose.Schema({
    topic: String,
    message: Number,
    when: Date
}, {collection: "sensordata"});

var sensordata =mongoose.model('sensordata', dataSchema);

//$HTTP GET function
app.get('/api/sensordata', function(req, res) {
    sensordata.find(function (err, data) {
        res.json(data);
    });
});

这是我将数据打印到控制台时得到的数据。 http://i67.tinypic.com/2rhlpwg.png数据页脚看不懂。

【问题讨论】:

  • 试试$scope.sensordatas = response.data;
  • 我应该对代码的哪一部分进行此更改?
  • 在您的 app.js 中,只需将 .data 添加到您的响应回调中。
  • 你是最棒的!!!非常感谢!
  • 那里太兴奋了。非常感谢*。

标签: javascript node.js mongodb angularjs-ng-repeat


【解决方案1】:

您能否在应用程序的 html 视图代码周围放置包装器

<div ng-app="app"><div class="container" ng-controller="FormController">
    <table class="table table-striped">
        <tbody>
        <tr ng-repeat="sensordata in sensordatas track by $index">
            <td>{{sensordata.topic}}</td> 
            <td>{{sensordata.message}}</td>
            <td>{{sensordata.when}}</td>
        </tr>
        </tbody>
    </table>
</div>

【讨论】:

  • 很抱歉没听明白。
猜你喜欢
  • 2016-03-03
  • 2019-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多