Home > Article > Web Front-end > Summary of angularjs methods for handling multiple asynchronous requests_AngularJS
In actual business, it is often necessary to wait for several requests to be completed before proceeding to the next step. But $http in angularjs does not support synchronous requests.
Solution 1:
Solution 2:
The methods in then will be executed in order.
getJson('json1.txt').then(function(){
return getJson('json2.txt');
}).then(function(){
return getJson('json1.txt');
}).then(function(){
return getJson('json2.txt');
}).then(function(d){
console.log('end');
});
});
Solution three:
The first parameter of the $q.all method can be an array (object). After the contents in the first parameter are executed, the method in then will be executed. All return values of the first parameter method will be passed in in the form of arrays (objects).
There are many tutorials on the Internet for detailed usage of $q. I'm new to it too. If you don't speak well, you don't dare to speak nonsense. The above code was written according to my understanding, and it has been tested without any problems.