I load a message which depends on whether the user logs in or logs out, but there is a problem, that it only shows me the login message in both cases. I use the method backView()
, which always gets the view before it is parked. Here is the code:
loading.js
angular.module('loadingPage', ['ionic', 'loginApp', 'historialApp'])
.controller('mostrarMensaje', mostrarMensaje)
.factory('obtenerVista', obtenerVista);
mostrarMensaje.$inject = ['$scope', 'obtenerVista'];
function mostrarMensaje($scope, obtenerVista) {
var vista_Anterior, valor_sesion;
vista_Anterior = obtenerVista.nombreVista();
if (vista_Anterior.stateName === "login") {
$scope.mensaje = "Cargando Informacion";
} else {
$scope.mensaje = "Cerrando sesion";
}
}
obtenerVista.$inject = ['$ionicHistory'];
function obtenerVista($ionicHistory) {
return {
nombreVista: function() {
var vista;
vista = $ionicHistory.backView();
return vista;
}
};
}
Here is a drawing to be more specific, if something is understood
Thanks in advance for the help.
I use another system that is still easier for you. It is about saving a value in localStorage to know if the user is logged in or not.
Just add in the login function:
and in the logout function:
So when displaying the message:
Well I was able to solve the problem as follows:
What happened was that loading.js varified what was in
window.localStorage.logged
only once, so it had to be entered multiple times for it to happenSo to solve it, I made use of view lifecycles, in this case use the event
$ionicView.beforeEnter
. activates it when entering the page ( load from cache or created for the first time ).