I execute a function that calls two functions sequentially in order to start the second function, first you need to complete the first. But this does not happen, possibly because the first function is asynchronous. I read that I need to use a "promise . " I tried it differently, but it does not work. So I rewrote the function, as I originally wrote:
function fail() {
var x = document.getElementById("snackbar")
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", "");}, 3000);
}
function _goback(){
$location.url('/app/dispensers');
}
function _checkavailability(response){
if (response.data == ""){
console.log("Accesso non autorizzato")
}
$scope.infoproductbyid = response.data;
if($scope.infoproductbyid.purchaseTime == null){
console.log("Item disponibile");
$location.url('/app/notregcheckout');
}
else{
console.log("Spiacente, item non più disponibile");
fail();
_goback();
}
}
, fail() , _goback() - . , _goback() , fail() , fail() -, , . ,