$ scope.init()에서 $ scope.email에 액세스하려면 어떻게해야합니까? 현재 그것은 나를 정의하지 않고 있습니다.Anglesjs의 init 함수에서 .then에 설정된 값에 액세스하는 방법은 무엇입니까?
app.controller('someCtrl',
[$scope,$http,$location,function($scope,$http,$location){
$scope.init = function(){
$scope.func1();
console.log($scope.email); // giving undefined
}
$scope.func1 = function(){
var data = {
'Content-Tye' : 'application/json',
'some-token' : $cookies.get('sometoken')
};
$http({
method : 'GET',
url : some url,
headers = data,
timeout: 50000
}).then(function(successData){
$scope.email = successData.entity.email;
}).then($http({
method:'GET',
url: some url,
headers: data,
timeout:50000
})
.then ..)
}
}])
나는 일련의 .the 나를 혼란스럽게합니다. $ scope.email이 설정 될 때까지 어떻게 기다려야합니까? 내 console.log 문은 설정되기 전에 실행됩니다. 어떻게 기다려야합니까? 나는 약속에 대해 읽었지 만, 혼란스러워하는 것은 나. 먼저 콘솔 로그를 완성 할 때까지 기다리고 싶습니다.
감사 니콜라스. 이 질문에 대한 답변입니다. –