2016-06-29 8 views
0

私は、getCurrentUser権限で返された値を取得しようとしています。関数を呼び出すと、私はこのリソースにPromiseを保持します。私はそこに_idの値を見ることができます!どのように私はそれにアクセスするのですか?NodeとAngularを使用して値の代わりにResourceオブジェクトを受け取ります。

ありがとうございます! Console Output

ここGETCURRENTUSERが定義されている認証サービスのビットです:私はそれを呼び出すのはここ

(function config() { 
    function AuthService($location, $http, $cookies, $q, appConfig, Util, User) { 
    const safeCb = Util.safeCb; 
    let currentUser = {}; 
    let Auth = {}; 
    const LOCAL_HOST = 'localhost'; 

    if ($cookies.get('token') && $location.path() !== '/logout') { 
     currentUser = User.get(); 
    } 

    Auth = { 
     getCurrentUser(callback) { 
     if (arguments.length === 0) { 
     return currentUser; 
     } 

     const value = currentUser.hasOwnProperty('$promise') ? currentUser.$promise : currentUser; 
     return $q.when(value).then(user => { 
     safeCb(callback)(user); 
     return user; 
     },() => { 
     safeCb(callback)({}); 
     return {}; 
     }); 
    } 
... 

は次のとおりです。

angular.module('toroApp').directive('csvreaderDirective', ['$http', function ($http, Auth) { 

     return { 
     controller(Auth) { 
      const currentUser = Auth.getCurrentUser(); 
      console.log(currentUser); 
     }, 
     compile(element, Auth) { 
    ... 
+0

urコードを表示してください。 – Wcan

答えて

0

Auth.getCurrentUser()あなたがそう$q promiseを返します結果を得るためにpromise APIを使用する必要があります。

controller(Auth) { 
    Auth.getCurrentUser().then(function (user) { 
     const currentUser = user; 
     console.log(currentUser); 
    }); 
} 
関連する問題