繁体   English   中英

玉不渲染变量以查看

[英]Jade not rendering variable to view

我正在复合复数课程中学习“使用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
    });
});

玉器

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"
  }

什么都没有显示,因为玉是基于压痕的。 您需要像这样将标签放入block main-content

block main-content
  section.content
    div(ng-view)
  h2= mongoMessage //this variable is not showing in the browser

而且我不确定代码的结构,但是如果要将h2包含在div中,则还需要缩进:

 block main-content
    section.content
      div(ng-view)
        h2= mongoMessage //this variable is not showing in the browser

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM