How to pass parameters and get them with $ state.go of angular?

1

I have the following code in the controller

app.controller('loginCtrl', ['$scope', '$stateParams', '$http', '$cordovaSQLite', '$window', '$state',

function ($scope, $stateParams, $http, $cordovaSQLite, $window, $state) {

$scope.clienteId = null;
$scope.clienteNome = null;
$scope.clienteEmail = null;

$scope.profId = null;
$scope.profNome = null;
$scope.profEmail = null;

$scope.logar = function(usuario){

    $scope.error = null;
    $scope.errors = {};

    $http.post("http://vigilantescomunitarios.com/serviapp/api_gustavo/login.php", usuario).success(function(response){
        //console.log(response);
        if(response == '' || response == [] || response == 'null'){
            $scope.msgErro = "E-mail ou senha inválido";
            return;

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

            var prof = response.e_profissional;
            var id = response.idusuario;
            var nome = response.nome;
            var email = response.email;

            if(prof == 1){
                $scope.profNome = nome;
                $scope.profEmail = email;
                $scope.profId = id;
                console.log($scope.profNome);

                $state.go('menuProfissional', { "nome": nome, "email": email, "id": id });
            }else{
                $scope.clienteId = id;
                $scope.clienteNome = nome;
                $scope.clienteEmail = email;
                console.log($scope.clienteNome);

                $state.go('menuCliente');
            }
        }

        })

     }

}])

And the controller where I'm going to get them

app.controller('menuProfissionalCtrl', ['$scope', '$stateParams', 'stateParams', function ($scope, $stateParams, stateParams) {

$state.params.nome;
console.log($state.params.nome);


}])

However, what appears on the console is "NaN"

What do I have to fix to get the name, email, and id?

    
asked by anonymous 10.05.2017 / 22:07

1 answer

1

To get the value you should use service $stateParams that will contain the value that was passed by $state.go . For example, in menuProfissionalCtrl :

...
console.log($stateParams.nome);
...

Tip: This link contains one a good practice manual that facilitates the maintenance and creation of code using Angular 1.x.

    
10.05.2017 / 22:20