查看 jQuery 文档我发现了以下内容:
$.get( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" ); <---
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
我需要在进行几次 ajax 调用后在 Angular Controller 中执行一个方法,如下所示:
$q.all([
$http.get(ROOT + "Lookup/GetStates"),
$http.get(ROOT + "Lookup/GetCountries"),
$http.get(ROOT + "Address/GetAddresses"),
]).then(function (results) {
$scope.states = jQuery.parseJSON(results[0].data.data);
$scope.country = jQuery.parseJSON(results[1].data.data);
$scope.addresses = jQuery.parseJSON(results[3].data);
});
then
执行后(仅在 then 之后) 我需要调用一个方法 $scope.setupControls()
这有可能吗?
最佳答案
为什么你不能这样做:
$q.all([
$http.get(ROOT + "Lookup/GetStates"),
$http.get(ROOT + "Lookup/GetCountries"),
$http.get(ROOT + "Address/GetAddresses"),
]).then(function (results) {
$scope.states = jQuery.parseJSON(results[0].data.data);
$scope.country = jQuery.parseJSON(results[1].data.data);
$scope.addresses = jQuery.parseJSON(results[2].data);
$scope.setupControls();
});
我觉得没必要二次成功。保持简单(和性感?)
关于javascript - 在 jQuery $.get() 中,angular $q.all() 是否有第二次成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29794441/