Created
July 19, 2015 21:35
-
-
Save JeremyMorgan/5b4b96d449769638e282 to your computer and use it in GitHub Desktop.
Magic Method
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
// 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