2016-06-22 5 views
-1

角度コントローラには2つの関数があります。通常、同じコントローラ内にあるので、他の関数から$ scope値にアクセスできるはずです。 2つのfunction.First関数で2つのconsole.log()を追加しました.First関数は、console.Butの値を2番目の関数で表示することができるため、スコープの値を取得します。この問題を解決する。続き角度範囲値は同じコントローラ内の別の関数からアクセスできません

は、私はthis.Iは角$ q.defer()メソッドを使用する必要が解決することができた私のコード、

まず機能

//Get user id 
    $scope.getUserId = function() { 
     UserService.getCurrentUser().then(function(response) { 
      if (response.query_status == "success") { 
       $scope.userid = response.data.id; 
       console.log('User id is: '+ $scope.userid); 
      } 
      else { 
       $scope.userid = null; 
      } 
     }, function(error) { 
      $scope.userid = null; 
      console.log("Error : Failed to load user data..."); 
      console.log(error); 
     }); 
    } 

セカンド機能

//Access user id 
    $scope.accessUserId = function() { 
     console.log('User id from other function is:'+ $scope.userid); 
    } 
+0

コードを掲載することはできますか? –

+0

コードスニペットを追加できますか? – Rohit

+0

申し訳ありませんが、コードで質問を更新しました。 – CodeCanyon

答えて

0

です。他の機能の応答を処理するための遅延がありました。

関連する問題