提到的脚本有什么用? [英] What is the use of the script mentioned?
问题描述
在样本meanjs应用程序上工作.我无法理解以下代码段. 请在layout.server.view.html视图中解释此脚本的用法.
working on the sample meanjs application. I am not able to understand the below code snippet. Kindly explain the use of this script in layout.server.view.html view.
<!--Embedding The User Object-->
<script type="text/javascript">
var user = {{ user | json | safe }};
</script>
推荐答案
基本上,每次对路由/*
发出请求时,都会通过express/swig发送user
(请参见
Basically user
is being sent via express/swig everytime a request is made to the route /*
(see here) so that user data can be used by AngularJS.
如果您检查文件core.server.controller.js
(此处),您将看到MEAN.JS在此代码块的响应中传递了一个用户对象:
If you check the file core.server.controller.js
(here), you will see that MEAN.JS passes a user object in the response in this code block:
res.render('modules/core/server/views/index', {
user: safeUserObject
});
然后在您提到的代码块中,将Express/Swig发送的用户对象分配给变量user
,随后可以使用$window.user
进行访问,类似于完成
Then in the code block you mentioned, you're assigning user object sent by express/swig to the variable user
which can then be accessed later using $window.user
similarly to what is done here.
json
和 safe
是两个swig过滤器.第一个返回JavaScript对象的字符串表示形式,第二个强制输入不自动转义.
json
and safe
are two swig filters. The first one returns a string representation of a JavaScript object and the second one forces the input to not be auto-escaped.
这篇关于提到的脚本有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!