var bar = dataService.makeHttpRequest("GET", "/documents/checkfilename/", null,
function (data, status, headers, config) {
// I can see `true` if I alert(data); here
// I want to return the contents of data because
// it's a true/false and would perform tasks based
// on it being true or false.
return data;
});
alert(bar); // this should alert `true` or `false` but is `undefined`
Why does alert(bar) always return undefined? I know that data in the above function has true or false, I am able to alert it; but, I want to return it and do things only when it is true.
The dataService.makeHttpRequest service function looks like the following:
dataService.makeHttpRequest = function(requestType, urlString, dataObject, successFunc, errorFunc) {
$http({
method:requestType,
url:$rootScope.serverAddress+urlString,
data:dataObject
})
.success(successFunc)
.error(errorFunc);
};
makeHttpRequestwhich doesn't return anything so you're gettingundefined.