Problems using $ state.go of angular

2

I have the following code:

.controller('cadastroCtrl', ['$scope', '$stateParams', '$http', function ($scope, $stateParams, $http, $cordovaSQLite, $window, $state) {

$scope.emailCli = [];
$scope.emailPro = [];

$scope.cadastrar = function(usuario){

    $http.post("http://ec2-54-68-29-61.us-west-2.compute.amazonaws.com/auth/register", usuario).success(function(response){

        var name = response.user.name;
        var email = response.user.email;
        var id = response.user.id;
        var is_professional = response.user.is_professional;    

        if(typeof(Storage) !== "undefined"){    

            if(is_professional == true){
                localStorage.setItem('userPro', name);
                $scope.emailPro = localStorage.setItem('emailPro', email);
                localStorage.setItem('idPro', id);

                console.log('Professional');

                $state.go('menuProfissional');
            }else{
                localStorage.setItem('userCli', name);
                $scope.emailCli = localStorage.setItem('emailCli', email);
                localStorage.setItem('idCli', id);

                console.log('Client');

                $state.go('menuCliente');
            }
        }else{
            console.log("Desculpe, mas o navegador nao possui suporte a Web Storage.");
        }

    })
}

}])

And no route.js

.state('menuCliente', {
    url: '/menuCliente',
    templateUrl: 'templates/menuCliente.html',
    controller: 'menuClienteCtrl'
  })

.state ('menuProfessional', {         url: '/ menuProfessional',         templateUrl: 'templates / menuProfessional.html',         controller: 'menuProfessionalCtrl'       })

And the following error message appears in the console:

  

Can not read property 'go' of undefined

What am I doing wrong?

    
asked by anonymous 30.03.2017 / 23:11

1 answer

6

Your initialization of the control is incomplete, and because of this the reference to $state is set to NULL .

You are using the providers declaration format in array , however only 3 out of 6 of the function interface are being declared.

Where to read:

.controller('cadastroCtrl', 
['$scope', '$stateParams', '$http', 
function ($scope, $stateParams, $http, $cordovaSQLite, $window, $state) {

Change to:

.controller('cadastroCtrl', 
['$scope', '$stateParams', '$http', '$cordovaSQLite', '$window', '$state',
function ($scope, $stateParams, $http, $cordovaSQLite, $window, $state) {
    
30.03.2017 / 23:18