-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);
}
コードを掲載することはできますか? –
コードスニペットを追加できますか? – Rohit
申し訳ありませんが、コードで質問を更新しました。 – CodeCanyon