Variables between cotroller


#1

.controller(‘LoginCtrl’, function($scope,$state,$http,$ionicPopup) {
$scope.loginn = function(){
var usuario = this.usuario; // asi se revise valores de html
var contrasena = this.contrasena;
$http.get(‘http://localhost:8000/exonerados/loginapp/’+usuario+’/’+contrasena+’’)
.success(function (response)
{
var valor = parseInt(response);
if(valor===1){
$ionicPopup.alert({
title: ‘Bienvenido’,
template: usuario
});
$state.go(‘app.sistemas’);
}else{
$ionicPopup.alert({
title: ‘Error’,
template: ‘Datos incorrectos’
});
$state.go(‘inicio’);
}

    });
   
}

})

.controller(‘SistemasCtrl’, function($scope, $stateParams) {

})

Good day, I need to be able to use the user variable throughout the application, is there a way to achieve this?


#2

You can read about creating service


#3

just go with the localstorage its may help you


#4

Hi! Look, you have some options to variables between controller, some bad choices, but…
you can:

  • Create services
  • Pass with $broadcast, $on,
  • $window, window
  • $rootScope