Skip to content

Instantly share code, notes, and snippets.

@philipmadeley
Last active September 16, 2015 01:59
Show Gist options
  • Save philipmadeley/6fba7993c1504540c5c9 to your computer and use it in GitHub Desktop.
Save philipmadeley/6fba7993c1504540c5c9 to your computer and use it in GitHub Desktop.
Example of using a promise in Angular
var makePromiseWithSon = function() {
// This service's function returns a promise, but we'll deal with that shortly
SonService.getWeather()
// then() called when son gets back
.then(function(data) {
// promise fulfilled
if (data.forecast === 'good') {
prepareFishingTrip();
} else {
prepareSundayRoastDinner();
}
}, function(error) {
// promise rejected, could log the error with: console.log('error', error);
prepareSundayRoastDinner();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment