티켓 관리 테이블을 만들고 있는데, 아약스 함수 밖에서 변수를 내보내려고 할 때 몇 가지 문제가 있습니다.각도 아약스, 함수 외부에 정의되지 않은 변수
내 코드 : 서버가 응답 할 때 공장
app.controller('bodyController',function($scope,$http,$sce){
$scope.ticketList = [];
$http.get("tickets.php")
.then(function(response) {
$scope.ticketModify = response.data;
console.log($scope.ticketModify); //this one return the correct data.
return $scope.ticketModify;
});
console.log($scope.ticketModify); //this return undefine
같은 결과 나는 .then
에서 실행 어떤 어떤 변수
모든 논리를 콜백 약속 콜백. – reptilicus
[비동기 호출의 응답을 어떻게 반환합니까?] (http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) 가능한 중복 –
GET은 console.log에서 계속 진행됩니다. 왜냐하면 함수가 비동기 적이기 때문에 실행되고 코드가 계속 될 수 있기 때문입니다. GET이 코드를 반환하면 그 부분에서 코드가 시작되고 절대 종료되지 않습니다. 그래서 console.log는 결코 다시는 발생하지 않습니다. 이미 좋은 대답이 있습니다. – jedi