freeCodeCamp/guide/chinese/miscellaneous/get-information-about-the-c.../index.md

16 lines
742 B
Markdown
Raw Normal View History

---
title: Get Information About the Current User in Angularjs
localeTitle: 获取有关Angularjs中当前用户的信息
---
您可能已经注意到,如果您打开**/client/app/admin/admin.controller.js** 它会调用_Auth_模块如下所示
```
.controller('AdminCtrl', function ($scope, $http, Auth …
```
您可以以相同的方式在其他控制器中包含Auth。在控制器中使用_Auth_可以检测用户是否已登录或获取有关当前用户的信息这非常有用。在控制器的主体中您可以添加
```
$scope.getCurrentUser = Auth.getCurrentUser;
$scope.isLoggedIn = Auth.isLoggedIn;
```
然后您可以在控制器的HTML视图中使用_isLoggedIn_或_getCurrentUser_