Last active
September 16, 2015 01:59
-
-
Save philipmadeley/6fba7993c1504540c5c9 to your computer and use it in GitHub Desktop.
Example of using a promise in Angular
This file contains hidden or 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
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