angularjs - 如何使用nodejs从 Angular 获取相当于 "req.something"的值

标签 angularjs node.js passport.js connect-flash

我正在学习如何使用 nodejs 和 Passport 设置身份验证的教程。 ( http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local )

教程让我使用 ejs 渲染模板并传入 flash 数据。

除此之外,我想使用 angularjs。我遇到问题的部分是获取闪存数据。我知道如何使用模板和发送变量,但是在下面的代码中用什么 Angular 替换了“req.flash('signupMessage')”?

这是教程显示的代码:

app.get('/signup', function(req, res) {
  // render the page and pass in any flash data if it exists
  res.render('signup.ejs', { message: req.flash('signupMessage') });    
});

这是我设置路线的代码

// public/js/appRoutes.js
angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

$routeProvider

    // show signup form
    .when('/signup', {
        templateUrl: 'views/signup.html',
        controller: 'SignupController'  
    });
$locationProvider.html5Mode(true);

}]);

这是 Controller :

 // public/js/controllers/SetupCtrl.js
 angular.module('SignupCtrl', []).controller('SignupController', function($scope) {
     $scope.tagline = 'TEST';
 });

最佳答案

此处回答了类似的问题:What is the proper way to log in users using Angular & Express?

TLDR:发布的答案指向以下链接,作者在其中描述您需要在服务器端保留所有 Passport 内容,然后允许客户端( Angular 内容)请求有关 session 的信息。 http://vickev.com/#!/article/authentication-in-single-page-applications-node-js-passportjs-angularjs

关于angularjs - 如何使用nodejs从 Angular 获取相当于 "req.something"的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25464798/

相关文章:

javascript - AngularJS ng-src 异步函数

node.js - 如何在 Docker 内的 80 端口上运行 node.js

arrays - 将数组名称作为 mongoose 中的参数传递

android - 向 Instagram 进行身份验证时不会重定向到回调 URL

node.js - Passport and JWT and Google Strategy - 谷歌回调后禁用 session 和 res.send()

javascript - Angular-moment js 显示的日期比实际日期更旧

javascript - 如何将此范围变量绑定(bind)到 ng-class 属性?

javascript - Browserify 在模块中需要模块

mysql - 使用 MySQL 在 PassportJs 中多个序列化用户

javascript - Angular UI 警报在 IE 8 上不起作用