How to send req.flash messages from node to Angular.js

你说的曾经没有我的故事 提交于 2019-12-25 06:35:30

问题


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)

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

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

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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/42903783/how-to-send-req-flash-messages-from-node-to-angular-js

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