【发布时间】:2014-10-17 08:34:38
【问题描述】:
我正在关注如何使用 nodejs 和护照设置身份验证的教程。 (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);
}]);
这里是控制器:
// public/js/controllers/SetupCtrl.js
angular.module('SignupCtrl', []).controller('SignupController', function($scope) {
$scope.tagline = 'TEST';
});
【问题讨论】:
-
Flash 数据是一个服务器端(实际上是基于会话的)构造。您不能只在 angularjs 中“使用闪存数据”,因为 angular 是在客户端而不是服务器上运行的。您必须将闪存数据从服务器传递到客户端,然后对其进行处理(我猜您的意思是显示它)给用户。 angularjs 中没有任何东西替换
req.flash。
标签: angularjs node.js passport.js connect-flash