Jade没有渲染变量来查看

时间:2016-04-02 00:00:43

标签: angularjs express pug mean

我正在使用MEAN堆栈"构建Angular和Node.js应用程序"当然在pluralSight。我是MEAN堆栈的新手,特别是后端,所以请原谅我,如果我是模糊的。所以这就是我发生的事情......我试图从Mongodb获取我的消息对象以显示使用jade。我没有收到任何错误,我实际上是从视频开头开始的,只是为了确保我第一次没有错过任何东西。如果您愿意,我可以提供具体细节。对于为什么这不起作用的任何想法都将不胜感激。

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

1 个答案:

答案 0 :(得分:1)

没有任何东西显示,因为玉是基于缩进。您需要将标记放在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