如何将req.flash消息从节点发送到Angular.js [英] How to send req.flash messages from node to Angular.js

查看:118
本文介绍了如何将req.flash消息从节点发送到Angular.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在跟踪有关如何使用nodejs和护照设置身份验证的教程( http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local )

I'm following a tutorial on how to set up authentication with nodejs and passport (http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local)

本教程具有带ejs的渲染模板,并传递Flash信息和错误消息.

The tutorial has rendering templates with ejs and passing in flash info and error messages.

相反,我喜欢使用angularjs.我遇到的问题是将Flash消息传递给客户端.我知道如何使用模板和发送变量,但是在下面的代码中用angle替换"req.flash('Message')"是什么?

Instead of this, I like to use angularjs. The part I'm having trouble with is getting the flash messages to client side angular. I know how to use templates and send variables, but what in angular replaces the "req.flash('Message')" in the below code?

app.get('/signup', function(req, res) {    
  res.render('signup.ejs', { message: req.flash('signupMessage') });    
});

什么是等效的或任何其他方法来显示我们的消息,例如从nodejs到angular的req.flash

What is the Equivalent or any other method to show our messages as like req.flash from nodejs to angular

推荐答案

req.flash 消息不是用于使用Angular或任何其他SPA框架的情况,而是用于在HTML上呈现HTML的情况后端,并在每次请求时将其发送给客户端.

The req.flash messages are not for situations where you use Angular or any other SPA framework but for situations where you render HTML on the backend and send it to the client on every request.

这将使您仅在启动Angular应用程序时或在浏览器中单击重新加载"时发送一次消息,而在您实际使用它时则仅发送一次.

This would let you sent a message only once when you start the Angular application or when you click Reload in your browser but not when you actually use it.

对于Angular这样的SPA,您需要使用AJAX或WebSocket或SSE等将有关错误的数据从服务器发送到客户端.

For SPAs like Angular you need to use AJAX or WebSocket or SSE etc. to send data from the server to the client about the errors.

这篇关于如何将req.flash消息从节点发送到Angular.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆