[英]How to retrieve ejs data sent from node server in an angular controller?
What is the best practice to retrieve ejs data that is sent from a res.render call from a node server? 检索从节点服务器的res.render调用发送的ejs数据的最佳实践是什么?
here is an example route from my server: 这是来自我的服务器的示例路由:
app.get('/', function(req, res){
res.render('index', {message: "hello"});
}
Do I need to instantiate the variable message in my ejs template? 我需要在我的ejs模板中实例化变量消息吗? or is there a way to retrieve the "message" field purely through the angular controller?
还是有一种方法可以完全通过角度控制器来检索“消息”字段? Thanks.
谢谢。
I've searched for the solution on a similar question on SO but it did not help. 我已经搜索了关于SO的类似问题的解决方案,但没有帮助。
I believe "res.render" doesn't pass any data to the client. 我相信“ res.render”不会将任何数据传递给客户端。 It takes the data you pass it, puts it into the EJS template, renders it, and sends that to the client.
它接收您传递的数据,将其放入EJS模板,进行渲染,然后将其发送给客户端。 For this reason, I'm pretty sure its impossible to retrieve this information through EJS.
因此,我非常确定不可能通过EJS检索此信息。 If you're looking to use AngularJS to data bind this info to the page, a better alternative may be to set up a RESTful API service on the server that can return this information.
如果您希望使用AngularJS将此信息数据绑定到页面,则更好的选择可能是在服务器上设置RESTful API服务以返回此信息。 Angular can then use AJAX to retrieve this information, and bind it to the page.
然后,Angular可以使用AJAX检索此信息,并将其绑定到页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.