I have a save function where i need to call another function to get revision num. and there am making api call. since both are async in nature . How to make one function to make wait until other executes
$scope.getRevision = function(callback){
Api.Product.querymyProdById({ prodId: $scope.editProdId }).$promise.then(function(result) {
if (result && result.length>=1 && result[0].effectiveDate != $scope.editProdmyDate) {
$scope.editProdRevision = result && result[0].revision +1;
callback();
} else {
$scope.editProdRevision = 100;
}
});
}
$scope.saveProd = function(){
$scope.getRevision(function(){});
Api.Product.save({
id: $scope.ProdId;
revision:$scope.editProdRevision
-some code
}
The above code i wanted to make sure save api should not get called until i get the prodRevision.
Any suggestion?