It seems like your situation involves a page where different sections are dependent on each other and served through separate http requests.
To address this issue, you can initiate the subsequent http request from the success callback of the initial http request, creating a chain of requests. For example:
servicePOST.send(appConstants.BASE_MS_URL + 'Dcrs/activityDay.php',{
"date":d
}).then(function(result) {
$scope.dcrlocked = result.dcrlocked;
$scope.leaves = result.leaves;
//$scope.holidays = result.holidays;
//initiate another http request as shown below.
servicePOST2.send(url,{data or data from previous request}).then(function(){
// initiate another http request and so forth.
})
});
By making all http requests within the success callbacks of preceding requests, you ensure a sequential flow of requests.
UPDATE
You can leverage $promise
in your secondary function that handles the post request. For instance:
var deferred = $q.defer();
servicePOST.send(appConstants.BASE_MS_URL + 'Dcrs/activityDay.php',{
"date":d
}).then(function(result) {
$scope.dcrlocked = result.dcrlocked;
$scope.leaves = result.leaves;
//$scope.holidays = result.holidays;
deferred.resolve(result);
});
return deferred; // return deferred from your function.
Remember to inject $q into your controller and pass it to the subsequent function. This adjustment enables the post function to execute synchronously. Please confirm if this aligns with your requirements.