Created
December 8, 2015 16:02
-
-
Save ericterpstra/e838f0e2b8429795b805 to your computer and use it in GitHub Desktop.
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 doStuffBeforeGettingData(stuff) { | |
return $q(function(resolve, reject) { | |
// Validate stuff. | |
if (stuffnotvalid) { | |
// Create error reasons | |
reject(reasons) | |
} else { | |
$http({ | |
method: 'GET', | |
url: '/someUrl' | |
}) | |
.then(function successCallback(response) { | |
resolve(respose); | |
}, function errorCallback(response) { | |
reject(respose); | |
}); | |
} | |
}); | |
} | |
// In a Controller or something... | |
$myService.doStuffBeforeGettingData(things) | |
.then(function(results){ | |
// do stuff with results | |
}, | |
function(error){ | |
// show error to user | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment