0

我正在使用MEAN 堆栈,我有这个疑问:

目前,在 chrome 的 angularjs 插件中检查,登录后,在全局范围内显示我的用户信息如下:

user: { 
    provider: local
    name: Usertest
    email: usertest@usertest.com
    username: User
    _id: 52f94e49088c92d972163f64
    __v: 0
    role: special_member
} 

如您所见,我已将该字段添加role到用户架构中。

我的问题是:为什么新角色字段出现在前端,而例如密码没有出现?(我知道它不会出现,但是在哪个文件中或在哪里明确指出某些字段不应传递给角度管理的前端?)。

4

1 回答 1

0

用户在app/views/index.html中被转移到 Angular :

<script type="text/javascript">
    window.user = {{user|safe}};
</script>

{{ user|safe }}将传递给app/controllers/index.js 中的模板:

res.render('index', {
    user: req.user ? JSON.stringify(req.user) : 'null'
});

您可以在此处拦截用户以仅传递某些值:

user: req.user ? JSON.stringify({ username: req.user.username, _id: req.user._id }) : 'null'
于 2014-02-12T19:28:38.723 回答