简体   繁体   English

如何在Angular模板中显示从Express传递的变量?

[英]How do I display variables passed from Express in an Angular template?

I have a variable that I passed from Express initially to a page which also uses AngularJS. 我有一个变量,最初是从Express传递给也使用AngularJS的页面的。 However when I try to access it with {{}}, it doesn't seem to appear. 但是,当我尝试使用{{}}访问它时,它似乎没有出现。 Does this only retrieve variables from the $scope? 这是否仅从$ scope检索变量? If so, how do I display other variables in AngularJS? 如果是这样,如何在AngularJS中显示其他变量?

You have to define values or constants. 您必须定义值或常量。 For example, put following code in before </body> . 例如,将以下代码放在</body>之前。

<script>
angular.module('your-module').constant('foo', 'bar');
angular.module('your-module').value('obj', {some: 1, encoded: {obj: 'xx'}});
</script>

Then you can inject foo and obj in your controllers/services respectively. 然后,您可以分别在控制器/服务中注入fooobj

暂无
暂无

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

相关问题 如何从 Express 中的 API 获取要在 Angular 中显示的数据? - How do I get data to display in Angular from API in Express? 如何在 angular 中实现模板变量? - how do I implement template variables in angular? 如何将模板中的内容传递到Express中的布局? - How do I pass content from a template to a layout in Express? "<i>How do I render a pug template on success and failure of authentication(passport.js) with variables from the pug template?<\/i>如何使用哈巴狗模板中的变量在身份验证(passport.js)成功和失败时呈现哈巴狗模板?<\/b> <i>(express, passport.js, pug)<\/i> (快递,passport.js,哈巴狗)<\/b>" - How do I render a pug template on success and failure of authentication(passport.js) with variables from the pug template? (express, passport.js, pug) 在 Express.js 中,如何让我的模板显示 flash 消息? - In Express.js, how do I make my template display the flash messages? 我们如何从 express session 中读取动态变化的值并在 angular 前端显示该值 - How do we read dynamically changing value from express session and display the value on angular front end 如何在Angular中使用Flask中的`render_template`? - How do I use `render_template` from Flask in Angular? 如何从Angular中的回调访问外部作用域变量? - How do I access outer scope variables from a callback in Angular? 如何在Meteor中传递模板变量? - How do I pass template variables in Meteor? 如何使用Express和MySQL将SQL查询的结果插入Pug模板中? - How do I insert results from an SQL query into a Pug template with Express and MySQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM