Last active
December 1, 2015 11:01
-
-
Save kikill95/0b4dbb6671e9a6b8b15a to your computer and use it in GitHub Desktop.
Promises
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
// real example | |
$ionicLoading.show(); | |
API.post(url, postObject, headers).then(() => { | |
$state.go(homeStateName); | |
$ionicPopup.alert({ | |
template: 'Some text' | |
}); | |
}).then($ionicLoading.hide).catch($ionicLoading.hide); | |
// Okay, that might be a little confusing, let me briefly explain: | |
/* code for start loader (spinner) */ | |
API.post(url, postObject, config).then((resolve) => { // arrow function (ES6) | |
// do something if success, for example show popup (modal), or change the location or update some info | |
}) | |
.then(/* function for hiding loader anyway (spinner) */) | |
.catch(/* function for hiding loader anyway (spinner) */); | |
// P.S. 'API' is my own AngularJS service, for this example you just need to know that 'API' returns a Promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment