I'm working on a small project using AngularJS and I'm making various asynchronous calls that are beginning to get messy. I know there has got to be a better way to make these calls but I'm not sure how. This is what I have:
asyncCall1(someArgument,function(asyncCall1Response) {
// do some stuff
asyncCall2(asyncCall1Response.someAttribute,function(asyncCall2Response) {
// do some more stuff
asyncCall3(asyncCall2Response.someAttribute,function(asyncCall3Response) {
// finish doing stuff...or maybe call asyncCall4?!
});
});
});
What is the correct way to use an asynchronous call's response as arguments being passed into another asynchronous call?
One way of handling asynchronous calls you can use $q. It returns multiple promises.