.controller('EntrarCtrl', function($rootScope, $scope, $stateParams, $http, $ionicPopup, $location, CONFIG, $ionicSideMenuDelegate) { $rootScope.userToken = ''; $scope.user={}; $scope.user.username=''; $scope.user.password =''; $scope.doLogin = function() { $http.post('http://pixelesp.api.herokuapp.com/login',$scope.user).then(function(resp) { console.log(resp.data); $rootScope.userToken = resp.data.token; $scope.user = $rootScope.user; $scope.user = {}; $http.get('http://pixelesp-api.herokuapp.com/me', {headers: {'auth-token': $rootScope.userToken}}).then(function(resp) { $rootScope.user = resp.data.data; console.log('token: '+$rootScope.userToken); console.log(resp.data.data); console.log('Succes', resp.data.data); }, function(err) { console.error('ERR', err); $location.path('/app/start'); // err.status will contain the status code }); $location.path('/app/inicio'); }, function(err) { console.error('ERR', err); var alertPopup = $ionicPopup.alert({ title: 'Error en el ingreso', template: 'Usuario o contraseƱa invalido' }); alertPopup.then(function(resp) { $location.path('/app/start'); }); // err.status will contain the status code }); }; $ionicSideMenuDelegate.canDragContent(false)