【发布时间】:2016-04-02 00:00:43
【问题描述】:
我正在复习“使用 MEAN 堆栈构建 Angular 和 Node.js 应用程序”课程。我对 MEAN 堆栈相当陌生,特别是后端,所以如果我含糊其辞,请原谅我。所以这就是我正在做的事情......我正在尝试从 Mongodb 获取我的消息对象以使用玉显示。我没有收到任何错误,实际上我已经从视频的开头重新开始,只是为了确保我第一次没有错过任何东西。如果你愿意,我可以提供具体的细节。任何关于为什么这不起作用的想法将不胜感激。
index.js
var messageSchema = mongoose.Schema({message: String});
var Message = mongoose.model('Message', messageSchema);
var mongoMessage;
Message.findOne().exec(function(err, messageDoc) {
mongoMessage = messageDoc.message; //this is where i'm grabbing the data from mongodb and assigning it to this variable, right?
});
app.get('/partials/:partialPath', function(req, res) {
res.render("partials/" + req.params.partialPath);
});
app.get('*', function(req, res) {
res.render('index', { //
mongoMessage: mongoMessage //this is the variable that is not showing
});
});
index.jade
extends ../includes/layout
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser
依赖项
"dependencies": {
"body-parser": "^1.15.0",
"bower": "^1.7.7",
"express": "^4.13.4",
"jade": "^1.11.0",
"mongoose": "^4.4.10",
"morgan": "^1.7.0",
"stylus": "^0.54.2"
}
【问题讨论】:
标签: angularjs express pug mean