my question is this, I'm learning AngularJS, and I'm doing the code for a login, where I've done factory's, but everything is in the same file (app.js) as shown below:
'(function () { var app = angular.module ('login', ['ngStorage']);
//factoria para guardar y eliminar sesiones con sessionStorage
app.factory('sesionesControl', function($sessionStorage){
return {
//obtenemos una sesión //getter
get : function() {
return $sessionStorage.LoginAIRSoftware;
},
//creamos una sesión //setter
set : function(val) {
return $sessionStorage.LoginAIRSoftware = val;
},
//limpiamos una sesión
unset : function() {
return $sessionStorage.LoginAIRSoftware = undefined;
}
};
});
//Controlador para loginForm
app.controller('loginForm', ['$scope', '$window', '$location', 'authUsers', 'sesionesControl',
function($scope, $window, $location, authUsers, sesionesControl){
$scope.inicio = function(){
if($scope.usuario === null || $scope.password === null){
$scope.mensajeError = "Uno o más campos se encuentran vacios";
$scope.mensajeShow = true;
}else{
authUsers.login($scope.usuario, $scope.password)
.success(function(res) {
if(res.data === 'Correcto'){
sesionesControl.set($scope.usuario);
$window.location.href = 'home.html';
}else {
$scope.mensajeError = "USUARIO y/o CONTRASEÑA invalidos. Intente nuevamente.";
$scope.mensajeShow = true;
return false;
}
})
.error(function(err) {
$scope.mensajeError = "Error al conectar con Servidor";
$scope.mensajeShow = true;
});
}
};
}]);
})();'
I would like to know how to separate the factory "sessionsControl" in another file called factorySesionesControl.js and that my app.js file can use it. I would put what I tried, but it is useless since it does not work, and for that I would appreciate your help.