如何通过Passport和nodeJS在angularJS前端显示用户信息

我试图复制这个本地身份validation与护照教程 。

但用angularJS前端,而不是EJS,直到现在一切正常,但我有一个问题,当我想显示用户数据在configuration文件页面(成功login后)

我正在谈论这段代码

// ===================================== // PROFILE SECTION ===================== // ===================================== // we will want this protected so you have to be logged in to visit // we will use route middleware to verify this (the isLoggedIn function) app.get('/profile', isLoggedIn, function(req, res) { res.render('profile.ejs', { user : req.user // get the user out of session and pass to template }); }); 

我知道用户是我需要的数据,但是在使用EJS的例子中是这样使用的:

 <!-- LOCAL INFORMATION --> <div class="col-sm-6"> <div class="well"> <h3><span class="fa fa-user"></span> Local</h3> <p> <strong>id</strong>: <%= user._id %><br> <strong>email</strong>: <%= user.local.email %><br> <strong>password</strong>: <%= user.local.password %> </p> </div> </div> 

我可以通过AngularJS访问这些相同的数据吗? 我在这方面有点新,而且我不明白

是的,您也可以在Angular中获取数据。 希望你已经引导你的angular度应用程序。 用这个:

本地

  <p> <strong>id</strong>: {{user._id}}<br> <strong>email</strong>: {{user.local.email}}<br> <strong>password</strong>: {{user.local.password}} </p> </div> </div> 

这个'用户'将使用你将在你的控制器中定义的范围variables

控制器function

 function test($scope) { $scope.user = user; //Need to get this user from the server call (by $http or a service) }