admin管理员组文章数量:1325108
I was looking for some way to know when two or more ajax calls have finished using AngularJS but I was only able to find it using jQuery:
$.when(promise3, promise5).done(
function(threeSquare, fiveSquare) {
console.info(threeSquare, fiveSquare);
}
);
and:
var promises = [
$.getJSON('square/2'),
$.getJSON('square/3'),
$.getJSON('square/4'),
$.getJSON('square/5')
];
$.when.apply($, promises).done(function() {
console.info(arguments);
});
is there any way to do something like this using AngularJS? Thanks for your support!
I was looking for some way to know when two or more ajax calls have finished using AngularJS but I was only able to find it using jQuery:
$.when(promise3, promise5).done(
function(threeSquare, fiveSquare) {
console.info(threeSquare, fiveSquare);
}
);
and:
var promises = [
$.getJSON('square/2'),
$.getJSON('square/3'),
$.getJSON('square/4'),
$.getJSON('square/5')
];
$.when.apply($, promises).done(function() {
console.info(arguments);
});
is there any way to do something like this using AngularJS? Thanks for your support!
Share Improve this question edited Nov 20, 2014 at 23:36 Deduplicator 45.7k7 gold badges72 silver badges123 bronze badges asked Jul 1, 2013 at 21:33 TomartoTomarto 2,7556 gold badges29 silver badges37 bronze badges1 Answer
Reset to default 9You will want to look at $q.all(); You can read about it here.
Here is a snippet:
all (promises)
Combines multiple promises into a single promise that is resolved when all of the input promises are resolved.
Parameters promises – {Array.} – An array of promises. Returns {Promise} – Returns a single promise that will be resolved with an array of values, each value corresponding to the promise at the same index in the promises array. If any of the promises is resolved with a rejection, this resulting promise will be resolved with the same rejection.
In version 1.1.x, you should be able to do something like this:
$q.all([
$http.get('square/2'),
$http.get('square/3'),
$http.get('square/4'),
$http.get('square/5')
]).then( function(arrayOfResponses) {
$log.info('all set');
$log.debug(arrayOfResponses);
});
Update:
As of version 1.1.6, you should be able to do the following:
var Square = $resource('square/:id', {id:1});
$q.all([
Square.get({id:2}).$promise,
Square.get({id:3}).$promise,
Square.get({id:4}).$promise,
Square.get({id:5}).$promise
]).then(function(arrayOfResponses) {
$log.info('all set');
$log.debug(arrayOfResponses);
});
本文标签: javascriptjQuery39s quotwhen()done()quot for AngularJSStack Overflow
版权声明:本文标题:javascript - jQuery's "$.when().done()" for AngularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742129555a2422095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论