I have a problem with the services in angular and it is that I am calling a function with request $ http.get inside a service that also makes request $ http.get.
This is my code when I check, if you see inside it there is a function called searchDeuda () which is what I want to finish first. How do you do that in Angular?
function consultar(cuenta) {
//Funcion que tambien hace una peticion $http
searchDeuda();
var config = {
params: {
cuentaNro: $scope.cuenta,
username: $scope.username
}
};
apiService.get('api/cuentasAsociadas/consultar/', config,
loadCompleted,
loadFailed);
}
function loadCompleted(result) {
if ($scope.conDeuda == true) {
$location.path('/arregloPago').replace();
} else {
notificationService.displayDialog("Aviso", 'Cuenta no posee Deudas', "OK");
}
}
}
function loadFailed(response) {
//notificationService.showConfirm('Aviso!!!', response.data, 'OK');
notificationService.showConfirm(this, 'Aviso!!!', response.data, 'AGREGAR CUENTA', 'OK')
.then(function () {
$location.path('/cuentasAsociadas/agregarCuenta').replace();
}, function () {
});
}
// Function that is within the request consult
function searchDeuda() {
var config = {
params: {
CuentaNro: $scope.cuenta
}
};
apiService.get('api/ArregloPago/Deuda/', config,
deudasLoadCompleted,
deudasLoadFailed);
}
function deudasLoadCompleted(result) {
if (result.data == 'Cuenta no posee Deudas') {
$scope.conDeuda = false;
} else {
$scope.conDeuda = true;
}
}
function deudasLoadFailed(response) {
notificationService.displayError('Error al buscar deuda');
}