When calling a function from my angular controller to make a $http.post() request, the code below the function call is executing before the successFunction(), preventing the code inside the if block from running. How can I ensure the if block executes without moving it to the successFunction()?
$scope.formSuccess = false;
$scope.submit = function(serviceName) {
submitRequest(serviceName);
if($scope.formSuccess) {
// do something
}
};
var submitRequest = function(serviceName) {
$http.post(serviceName, data, { headers: { 'Content-type': 'application/json' }
}).then(successFunction, errorFunction);
};
var successFunction = function(response) {
$scope.formSuccess =true;
};