0

Here is my example this is working fine:

var first  = $http.get("/app/data/first.json"),
    second = $http.get("/app/data/second.json"),
    third  = $http.get("/app/data/third.json");

$q.all([first, second, third]).then(function(result) {
  var tmp = [];
  angular.forEach(result, function(response) {
    tmp.push(response.data);
  });
  return tmp;
}).then(function(tmpResult) {
  $scope.combinedResult = tmpResult.join(", ");
});

Here the first, second and third all work alone without depended. In case for example, 'secondrequires someidfromfirstandthirdrequires somedatafromsecond... then how to initiate therequest` with depend on other?

var first  = $http.get("/app/data/first.json"), //fetching id
    second = $http.get("/app/data/second.json"), //needs some id from first
    third  = $http.get("/app/data/third.json"); //needs some data from second

How that should be handled. also, the query will from by series of adding the request or by series of adding in $q.all.

any one explain me with updating my code please?

1 Answer 1

2
first.then(function(data1){
  second.then(data2){
    third.then(data3){

    });
  });
});

first,second and third are your promises. Error can be received in second callback function like so.

promise.then(function(successData){
  // success here
}, function(errorData){
  // error here.
});
Sign up to request clarification or add additional context in comments.

2 Comments

How to get the error message here? q.all not required here
since your one request is dependent on the other, you can't use q.all. you can use q.all only if any request doesn't depend on the output from other requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.