在index.html中获取用户ID

时间:2017-07-23 10:07:35

标签: javascript html angularjs

我希望能够使用angular到index.html页面获取用户ID。但我无法使用下面的代码。出于某种原因,我能够获得用户名,电子邮件和其他值,但不能获得_id。有人可以帮帮我吗?

<a ng-show="main.isLoggedIn" class="page-scroll" href="/mytests/{{ main.getId }}">My tests</a>
    // Check if user is logged in
    if (Auth.isLoggedIn()) {
        // Custom function to retrieve user data
        Auth.getUser().then(function(data) {
            if (data.data.username === undefined) {
                app.isLoggedIn = false; // Variable to deactivate ng-show on index
                Auth.logout();
                app.isLoggedIn = false;
                $location.path('/');
            } else {
                app.isLoggedIn = true; // Variable to activate ng-show on index
                app.username = data.data.username; // Get the user name for use in index
                checkLoginStatus = data.data.username;
                app.useremail = data.data.email; // Get the user e-mail for use in index
                app.test1 = data.data.test1;
                app.getId = data.data._id; 

0 个答案:

没有答案