I am migrating an application to angular, but I got a bit involved with the routes, especially with the sub-routes, which I have the following problems and doubts:
Structure of my application
The passage of the index to the loading is done, also the menu and views, but the error always occurs to always load the teachers' menu first, I suppose it could be by the order of the folders of the templates.
My doubts would be:
Structure
Module
angular.module('unicesarApp', ['ionic'])
.controller('formulario', formulario)
.service('obtenerDatos', obtenerDatos)
.config(config);
Config
config.$inject = ['$stateProvider', '$urlRouterProvider'];
function config($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/login");
$stateProvider
.state('login', {
url: '/login',
templateUrl: "Templates/login.html",
controller: "formulario"
})
.state('Loading',{
url: '/loading',
templateUrl: "Templates/loading.html"
})
.state('menuestu',{
url: '/menuestu',
templateUrl: "Templates/Estudiante/menuestu.html"
})
.state('perfilestu',{
url: '/perfilestu',
templateUrl: "Templates/Estudiante/perfilestu.html"
})
.state('horarioestu',{
url: '/horarioestu',
templateUrl: "Templates/Estudiante/horarioestu.html"
})
.state('calificaciones',{
url: '/calificaciones',
templateUrl: "Templates/Estudiante/calificaciones.html"
})
.state('menuprof',{
url: '/menuprof',
templateUrl: "Templates/Docente/menuprof.html"
});
};
Controller
formulario.$inject = ['$scope', 'obtenerDatos', '$state'];
function formulario($scope, obtenerDatos, $state){
$scope.login = function(){
var datos, datosRespuesta;
datos = {
Usuario: $scope.usuariotxt,
Password: $scope.passwordtxt
};
if(datos.Usuario == undefined && datos.Password == undefined){
$scope.respuesta = "Los campos estan vacios";
}else{
obtenerDatos.Autenticacion(datos).then(function (response){
if(response.data){
datosRespuesta = response.data;
if(datosRespuesta === "Usuario no registrado"){
$scope.respuesta = datosRespuesta;
}else if(datosRespuesta === "Contraseña incorrecta"){
$scope.respuesta = datosRespuesta;
}else if(datosRespuesta.estudiante){
obtenerDatos.getDatos(datosRespuesta);
$state.go('Loading');
setTimeout(alerta, 3000);
function alerta(){
$state.go('menuestu');
};
}else{
obtenerDatos.getDatos(datosRespuesta);
$state.go('Loading');
setTimeout(alerta, 3000);
function alerta(){
$state.go('menuprof');
};
};
}else{
console.log(response.status);
$scope.respuesta = response.status;
};
});
};
};
};
Services
obtenerDatos.$inject = ['$http', '$httpParamSerializer'];
function obtenerDatos($http, $httpParamSerializer){
var datosIngreso;
function Autenticacion(datos){
var url = 'http://190.109.185.138/Apipedro/api/login';
return $http.post(url, $httpParamSerializer(datos), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
};
function getDatos(info){
datosIngreso = info;
};
function setDatos(){
return datosIngreso;
};
return {
Autenticacion: Autenticacion,
getDatos: getDatos,
setDatos: setDatos
};
};