0
我試圖登錄認證後,消息變量傳遞給我的EJS模板:表達角EJS傳遞變量到模板
app.post('/login', passport.authenticate('local-login', {
successRedirect : '/profile',
failureRedirect : '/login',
failureFlash : true
}));
然後代碼在get塊:
if(req.isAuthenticated()) res.render('partials/' + name, { message: 'test' });
所以,如果登錄失敗,用戶將被通知。局部的login.ejs會顯示消息,但消息未在模板中顯示:
<script>var message = "<%=message%>";</script>
<div class="col-sm-6 col-sm-offset-3">
<h1 class="form-fonts"><span class="fa fa-sign-in"></span>Login</h1>
<!-- show any messages that come back with authentication -->
<div ng-if="message.length > 0" class="alert alert-danger">{{message}}</div>
然而,當我看到在控制器中記錄的信息:
app.controller('LoginCtrl', ['$scope', '$http',
function($scope, $http) {
console.log('message: ' + message); // outputs message: test
}]);