简体   繁体   English

如何在角度控制器中检索从节点服务器发送的ejs数据?

[英]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.

相关问题 如何在悬停时用从节点 js 控制器发送的变量替换 EJS 模板中的文本? - How do I replace text in an EJS template on hovering with a variable sent from a node js controller? 如何使用前端ajax通过post方法发送的node.js在服务器端检索数据? - How to retrieve data on server side with node.js sent by frontend ajax via post method? 如何从通过jQuery Ajax调用发送到控制器的序列化表格数据中检索特定列表 - How to retrieve a particular list from serialzed form data sent to controller through jquery ajax call 如何使用Node JS服务器在EJS或Jade中发送和使用数据? - How to send and use data in ejs or jade with node js server? 从节点到角度检索数据时出现Cors错误 - Cors error on data retrieve from node to angular 如何将数据从EJS模板传递到AngularJS控制器 - How to pass data from EJS template to AngularJS controller 如何在角度4中调用httpclient的get方法从服务器检索数据? - how to call get method of httpclient in angular 4 to retrieve data from server? 如何检索节点中通过HTTPS发送的表单数据? - How to retrieve form data sent over HTTPS in node? 绑定从控制器发送的数据以查看angular.js失败 - Failed to bind data sent from a controller to view angular.js 如何在EJS / node.js中检索数据对象的属性? - How can I retrieve the properties of a data object in EJS/node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM