Skip to content

Instantly share code, notes, and snippets.

@JeremyMorgan
Created July 19, 2015 21:35
Show Gist options
  • Save JeremyMorgan/5b4b96d449769638e282 to your computer and use it in GitHub Desktop.
Save JeremyMorgan/5b4b96d449769638e282 to your computer and use it in GitHub Desktop.
Magic Method
// Send Request Method
sendRequest = {
async: function (url, method, param) {
// $http returns a promise, which has a then function, which also returns a promise
var promise = $http.get(url).then(function (response) {
// The then function here is an opportunity to modify the response
// store the response status and text
tmpData.requestStatus = response.status;
tmpData.requestStatusText = response.statusText;
// The return value gets picked up by the then in the controller.
return response.data;
});
// Return the promise to the controller
return promise;
}
var requestUrl = "http://www.whatever.com"
// send the request
sendRequest.async(requestUrl, "delete").then(function(data) {
tmpData.returnData = data;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment