I have two functions is_exist() and save() functions. In save function I calls is_exist() function before performing a save.it return boolean value. but my problem is save() function is not wait until is_exist() function to return the value.after is_exist() function called it just jump into next line and continue execute bellow lines, after save() finished is_exist() function return the value
var app = angular.module('my_app', [])
app.controller('my_con', ['$scope', '$http', function($scope, $http) {
$scope.save = function(sector) {
var del_status = $scope.is_exist(sector);
console.log(del_status); // is_exsis return value
if(!del_status) {
// save
}
}
$scope.is_exist = function(sector) {
$http({
method : 'POST',
url : '/is_data_exist',
contentType : 'application/json; charset=utf-8',
data : angular.toJson({
'sector': sector
}),
dataType: 'json',
}).then(function successCallback(response) {
console.log(response.data); //http respond
if(response.data == 'False') {
return false;
}
else {
return true;
}
})
}
}])
is there any way to wait until is_exsis() function to return value and then go to next line