Why can not I use $ window.localStorage.setItem () with angle?

0

After registering, I'm temporarily wanting to put some data in localStorage, but I'm not getting it.

Follow my code:

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

$scope.email = [];

$scope.cadastrar = function(usuario){

$http.post("http://vigilantescomunitarios.com/serviapp/api_gustavo/register.php", usuario).success(function(response){

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

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

        if(is_professional == 1){
            $window.localStorage.setItem('userPro', nome);
            $scope.email = $window.localStorage.setItem('emailPro', email);
            $window.localStorage.setItem('idPro', id);

            console.log('Profissional');

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

            console.log('Cliente');

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

    })
}

}])

Neitherthelocalurldoesnotappear"localhost: 8080 ..."

    
asked by anonymous 15.05.2017 / 22:30

1 answer

0

Try to save the item in the localStorage, turn it into String

 $window.localStorage.setItem('emailPro', JSON.stringify(email))

Then to recover you use this function to transform into an object again:

JSON.parse($window.localStorage.getItem('emailPro'))
    
16.05.2017 / 16:33