Skip to content

Instantly share code, notes, and snippets.

@geoffreybauduin
Last active May 10, 2016 20:56
Show Gist options
  • Save geoffreybauduin/ea5b2e633463f87aacf2bbf61d5ee8c6 to your computer and use it in GitHub Desktop.
Save geoffreybauduin/ea5b2e633463f87aacf2bbf61d5ee8c6 to your computer and use it in GitHub Desktop.
Using $q promises in Angular.js
function fn1 () {
var deferred = $q.defer();
$http.get("http://a.com/first").then(function (response) {
$http.get("http://a.com/second").then(function (response) {
deferred.resolve(response);
}, function (response) {
deferred.reject(response);
});
}, function (response) {
deferred.reject(response);
});
return deferred.promise;
}
fn1().then(function (response) {
console.log("success");
}, function (response) {
console.log("failure");
});
fn1().then(function (response) {
console.info("another success");
}, function (response) {
console.info("another failure");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment