1
我無法獲取控制器中的當前用戶標識。我有這樣的:Angular-Fullstack獲取當前用戶
controller.js:
constructor(Auth) {
this.getCurrentUser = Auth.getCurrentUserSync;
// console.log(this.getCurrentUser()._id) returns undefined
}
但是,如果我在HTML打印:
p {{ctrl.getCurrentUser()._id}}
我得到完美的用戶ID。
這是怎麼發生的?我如何獲得控制器中的用戶ID?
編輯:
的Auth.getCurrentUser()
功能看起來像:
function getCurrentUser(callback) {
var value = _.get(currentUser, '$promise') ? currentUser.$promise : currentUser;
return $q.when(value).then(function (user) {
safeCb(callback)(user);
return user;
}, function() {
safeCb(callback)({});
return {};
});
}
但是,獲取當前用戶標識的最佳方式是?我認爲這可能會更容易... – nash
是的,如果它的一個對象,這是你如何訪問 – Sajeetharan
對不起,訪問像我得到的'錯誤︰userinfo。$$ state.value是未定義'。我的意思是,Angular-Fullstack爲您提供了getCurrentUser函數,它應該很容易地返回用戶數據,不是嗎?不知道它是如何工作的... – nash