Last active
May 10, 2016 20:56
-
-
Save geoffreybauduin/ea5b2e633463f87aacf2bbf61d5ee8c6 to your computer and use it in GitHub Desktop.
Using $q promises in Angular.js
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
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