-1
각도 컨트롤러에는 두 개의 함수가 있습니다. 보통 같은 컨트롤러에 있기 때문에 다른 함수에서 $ scope 값에 액세스 할 수 있어야합니다.하지만 그것에 액세스 할 수 있습니다. 두 function.First 함수에서 두 console.log() 추가했습니다. 그것은 두 번째 함수에서 console.But 값을 인쇄 할 볼 수 있기 때문에 범위 값을 검색합니다. 그것은 정의되지 않은 variable.Hope 누군가가 나를 도울 것입니다. 이 문제를 해결하십시오. 각도 범위 값이 같은 컨트롤러의 다른 함수에서 액세스 할 수 없습니다
다음
내 코드,첫 번째 기능
//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