angularjs - Clear rootscope ionic framework -
hi i'm doing login ionic app.....and i'm using rootscope global variable use in controller (loginctrl,salirctrl) when user log-in save info in rootscope variable , show info in salirctrl.
but when user log-out , other user log-in info not present in salirctrl.
someone knows that.
loginctrl
if($scope.datos=='true') {//if token true. user log-in $rootscope.pnombre=data.persona.primernombre; $rootscope.snombre=data.persona.segundonombre; $rootscope.papellido=data.persona.primerapellido; $rootscope.sapellido=data.persona.segundoapellido; $state.go('tabs.perfil'); }
salirctrl
.controller('salirctrl', function($scope, $state, $ionicpopup, servusuario,$rootscope,$ionichistory) { //para bloquear el boton atras $ionichistory.nextviewoptions({ disableanimate: true, disableback: true }); //fin para bloquear el boton atras $scope.pnombre = $rootscope.pnombre;//save in scope variable rootscope $scope.snombre = $rootscope.snombre; $scope.papellido = $rootscope.papellido; $scope.sapellido = $rootscope.sapellido; //metodo salir $scope.salir = function() { var confirmpopup = $ionicpopup.confirm({ title: 'log-out', template: '¿log-out?' }); confirmpopup.then(function(res) { if(res) { console.log('you sure'); $state.go('login'); $scope.pnombre=" "; //when log-out true. variables equals empty $scope.snombre=" "; $scope.papellido=" "; $scope.sapellido=" "; } else { console.log('you not sure'); } }); }; //fin metodo salir })
finally print variables in perfil.html
{{pnombre}} {{snombre}} {{papellido}} {{sapellido}}
thanks....!
my guess you're suffering caching in angularjs ui-router. in route config, happens when this?:
$stateprovider.state('mystate', { cache: false, url : '/myurl', templateurl : 'my-template.html' })
by default ionic caches views described here:
http://ionicframework.com/docs/api/directive/ionnavview/
when views cached controllers don't reload during navigation. let me know if did trick?
best,
Comments
Post a Comment