问题
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