I would like to know how to wait until the execution of one service is finished before another is executed, this is because what the first service returns is necessary for the execution of the 2nd.
Here is my service and my controller.
configSrv.js
var app = angular.module('form.configSrv', []);
app.factory('configSrv', ['$http','$q', function ($http,$q) {
var self = {
config: {},
load_config:function(){
var d = $q.defer();
$http.get('config.json')
.then(function(resp){
self.config = resp;
d.resolve();
})
.catch(function(){
d.reject();
console.error("No se pudo cargar el archivo de configuracion :(");
});
return d.promise;
}
};
return self;
}]);
And my controller:
var app = angular.module('form.formCtrl', ['banecform.configSrv']);
app.controller('formCtrl',
['$scope', 'sdmLogin', 'sdmQuery', 'sdmHandle', 'sdmCreate', 'sdmLogOut', 'sdmUploadFile', 'configSrv',
function ($scope, sdmLogin, configSrv) {
configSrv.load_config().then(function() {
$scope.config = configSrv.config;
});
sdmLogin.sdmLogin($scope.config.data.user, $scope.config.data.password).then(function () {
$scope.loginToken = sdmLogin.login_token;
});
}]); // Fin de Ctrl
As seen in the code, my intention is to run sequentially. I have tried nesting them, but then that creates complications for me since I need to logout when everything (other services) has finished and the logout service runs ahead of time.
I hope you can help me, regards.