Skip to content

Instantly share code, notes, and snippets.

@kikill95
Last active December 1, 2015 11:01
Show Gist options
  • Select an option

  • Save kikill95/0b4dbb6671e9a6b8b15a to your computer and use it in GitHub Desktop.

Select an option

Save kikill95/0b4dbb6671e9a6b8b15a to your computer and use it in GitHub Desktop.
Promises
// 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