What is the use of the script mentioned?

北慕城南 提交于 2019-12-12 03:44:52

问题


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>

回答1:


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.

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
});

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 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.



来源:https://stackoverflow.com/questions/37519300/what-is-the-use-of-the-script-mentioned

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!