If you're aiming to achieve your desired outcome, it's crucial to delve into the world of angularJS promises, particularly since the POST request operates asynchronously. Be sure to refer to this resource for more insights:
http://www.webdeasy.com/javascript-promises-and-angularjs-q-service/
The key concept revolves around initiating a call that yields a deferred object as an initial step, resembling something along these lines:
this.myFunction = function (myForm) {
var deferred = $q.defer();
$http.post(myURL, myForm)
.success(function (data) {
//resolve the promise
deferred.resolve('SUCCESS');
})
.error(function (data) {
//reject the promise
deferred.reject('ERROR');
});
//return the promise
return deferred.promise;
}
Subsequently, execute the call in this manner:
var myPromise = this.myFunction ($scope.modalForm);
// await the resolution or rejection of the promise
//"then" encompasses 2 functions (resolveFunction, rejectFunction)
myPromise.then(function(resolve){
// conduct operations here, confirming the completion of the post request
}, function(reject){
return;
});
Alternatively, any actions you wish to take after the POST request can be embedded within the success function of the request.