I am trying to call a function but it returns undefines. However, the log shows the proper expected data.
app.controller('checkoutCtrl', function($scope, $http, $rootScope){
$scope.finalizeOrder = function(){
if($scope.ordersubmitform.$valid){
//check if postal is valid
alert($scope.thepostal($scope.customer.postal));
}
}
$scope.thepostal = function(postal){
$http({
method: 'GET',
url: baseurl + 'api/verify_postal/' + postal,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
console.log(response.data.postal);
return(response.data.postal);
}, function errorCallback(response) {
});
}
});
The alert simply pops "undefined". However the console.log logs the expected answer.
Any idea?
I am not sure if using a service/factory is proper coz upon first calling the service/factory, I would get only its reference with out the function actually being called even if I try a different postal code. Sorry if I have gotten the whole singleton idea wrong.