【发布时间】:2017-05-08 13:02:24
【问题描述】:
我的服务器端运行了两个猫鼬模式。我想在我的 app.js 中添加两个$http.get 请求,并最终在网页上显示我在 MongoDB 中的集合中的两个表。只调用了一个get 函数而没有错误。
server.js
//Data Schema
var tempSchema = new mongoose.Schema({
topic: String,
message: Number,
when: Date
}, {collection: "temperature"});
var humiditySchema = new mongoose.Schema({
topic: String,
message: Number,
when: Date
}, {collection: "humidity"});
var temperature =mongoose.model('temperature', tempSchema);
var humidity =mongoose.model('humidity', humiditySchema);
app.js
app.controller("FormController", function ($http, $scope){
$http.get("/api/temperature")
.then(function (response) {
$scope.temperatures = response.data;
});
})
app.controller("FormController", function ($http, $scope){
$http.get("/api/humidity")
.then(function (response) {
$scope.humiditys = response.data;
});
})
还考虑如何在网页上显示这两个集合。使用ng-repeat。不幸的是,我无法在此处粘贴我的 HTML 代码。
如果能得到任何帮助,我将不胜感激。谢谢
【问题讨论】:
-
你已经定义了两次FormController。
-
索引是否与应该放在一起的数据匹配?所以
temperatures[0]会和humiditys[0]一起使用? -
@jbrown 我应该删除他们吗?
-
您应该将 ajax 调用放在服务中而不是控制器中
-
@ProfessorAllman 对不起,先生,我对这个平台还很陌生,请您说的更清楚一点。
标签: javascript angularjs node.js routing mongoose-populate