계속하기 전에 오류에 대한 매개 변수 배열을 테스트해야하는 함수가 있습니다. 항목에 따라 테스트에 서버 호출이 포함될 수도 있고 포함되지 않을 수도 있습니다.
저는 테스트 결과를 평가하기 전에 모두 끝내기 위해 $ q 배열을 구현했습니다. $ q.all을 사용하여 배열을 반환합니다.
나는 각 단계를 밟아서 해결책을 볼 수 있기 때문에 모든 약속이 해결되고 있음을 알고 있습니다. 그러나 어떤 이유로 든 해결책은 최상위에 도달하지 못합니다.
최상위 그 때는 :
$scope.BigTest().then(function(result){
//examine the array of results & then call the function we want to execute
// we never ever reach here
},
function(error){
// handle the error
// we never ever reach here either
});
함수 $ 사용 ● 모든() 다음 psuedocode에 명시된 바와 같이
$scope.BigTest = function(){
var promises = new Array();
for (var x = 0; x < $scope.testingStuff.length; x ++){
var temp = $q.defer();
if ($scope.testingStuff[x].localTestingGoodEnough){
if (test){
temp.resolve(true);
}
else{
temp.resolve(false);
}
}
else{
var getServerStuff = ServerService.testServer($scope.testingStuff[x]);
getServerStuff.then(function(result){
// I've debugged through here and know this is successfully happening whenever necessary, and that the value is appropriate
temp.resolve(result.value);
},function(error){
temp.resolve(false);
});
}
promises[x] = temp.promise;
}
return $q.all(promises);
}
이 문제는 약속의 전체 어레이가 결코 존재하지된다는 것이다 테스트에 서버 호출이 필요할 때 해결됩니다.
서버 호출이 필요하지 않은 경우에는 예상대로 설정됩니다.
이유가 해결되지 않는 이유는 무엇입니까? 아마도 $ q.all()을 제대로 사용하지 않고 있을까요?
시도'temp.resolve (result.data.value);'... 귀하의 서비스가'$ http'를 사용하고 있다고 가정하십시오. – charlietfl