Last active
September 28, 2016 17:40
-
-
Save papodaca/67b00f5f933984abd931d1c83653561e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//callbacks | |
$http.get(somepath, function(res, err) { | |
$http.get(somepathother, function(res2, err2) { | |
$http.get(somepathotherother, function(res3, err3) { | |
//dostuff | |
}); | |
}); | |
}); | |
//promises | |
var promises = []; | |
promises.push($http.get(somepath), $http.get(somepathother),$http.get(somepathotherotehr)); | |
$q.all(promises).then(function(resp) { | |
var res = resp[0], | |
res2 = resp[1], | |
res3 = resp[2]; | |
//do stuff | |
}); | |
//sequentially | |
function get1() { | |
return $http.get(somepath).then(function() { | |
//do stuff | |
}); | |
} | |
function get2() { | |
return $http.get(somepathother).then(function() { | |
//do stuff | |
}); | |
} | |
function get3() { | |
return $http.get(somepathotherother).then(function() { | |
//do stuff | |
}); | |
} | |
//callthem | |
get1().then(get2).then(get3); | |
//still possible to christmas tree ;) | |
$http.get(somepath).then(function() { | |
//do stuff | |
$http.get(somepathother).then(function() { | |
//do stuff | |
$http.get(somepathotherother).then(function() { | |
//do stuff | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment