Email is not appearing in the field due to Angular

0

Good afternoon guys,

I have an app, which, after the registration made it goes to the login screen. However, the email does not appear in the form as it should.

login controller:

.controller('loginCtrl', function ($scope, $http, $state, $location, $window) {

$scope.usuario = {
        email: $window.localStorage.getItem('emailLogin')
      };

$scope.mensagem = [];
$scope.msgErro = '';
$scope.msgExiste = '';
$scope.mensagens = [];
$scope.disableButton = false;
$scope.disableButtonChat = true;
$scope.denuncia = [];

$scope.logar = function (usuario) {

    $http.post("http://localhost:8888/sistemas/sistemas_web/ionic/vcApp/www/php/login.php", usuario).success(function (response){

        if(response == ''){
            $location.path('/page10');
            $scope.msgErro = "E-mail ou senha inválido";

        }else if(typeof(Storage) !== "undefined") {
            $window.localStorage.setItem("idUsuario", response.idUsuario);
            $window.localStorage.setItem("idCep", response.idCep);
            $window.localStorage.setItem("nome", response.nome);
            $window.localStorage.setItem("usuario", response.usuario);
            var idcep = response.idCep;

            $http.get("http://www.vigilantescomunitarios.com/www/php/dadosCep.php?idcep="+idcep).success(function (data){
                //console.log(data);
                $window.localStorage.setItem("estado", data.uf);
                $window.localStorage.setItem("cidade", data.cidade);
                $window.localStorage.setItem("bairro", data.bairro);
                $window.localStorage.setItem("logradouro", data.logradouro);
            })

            $location.path('/page10');
        } else {
            console.log("Desculpe, mas o navegador nao possui suporte a Web Storage.");
        }
    })
}
})

user registration controller

.controller('usuarioCtrl', function ($scope, $http, $window, $location) {

$scope.salvaUsuario = function (usuario) {
    // O cep é pego para salvar junto com os dados do usuário
    var idCep = $window.localStorage.getItem('idCep');
    usuario.idCep = idCep;

    $http.post("http://http://localhost:8888/sistemas/webApps/ionic/vcApp/www/php/salvaUsuario.php", usuario).success(function (data){

        $window.localStorage.setItem("emailLogin", data.email);

        if(data.cod === 1){
            $location.path('/cadastraUsuario');
            $scope.msgExiste = "Usuário já existente. Tente outro.";
        }

    });
    $location.path('/page10');
}
})

Login screen HTML

<ion-view title="Login" hide-back-button="true">
<ion-content overflow-scroll="true" padding="true" class="has-header">
    <form class="list">
        <ion-list>
            <div ng-controller="loginCtrl">
                <label class="item item-input">
                    <input type="text" ng-model="usuario.email" placeholder="E-mail">
                </label>
                <label class="item item-input">
                    <input type="password" ng-model="usuario.senha" placeholder="Senha">
                </label>
            </ion-list>
            <div class="spacer" style="height: 40px;"></div>
            <button class="button button-block button-positive" ng-click="logar(usuario)">Entrar</button>

            <a href="#/cadastroCep" class="button button-block button-positive">Cadastre-se</a>
            <div align="center">{{msgErro}}</div>
            </div>
    </form>
</ion-content>

And the email is being saved in the localStorage, as shown in the image

    
asked by anonymous 15.04.2016 / 21:05

1 answer

-1

You can use the localStorage.getItem('emailLogin'); Putting it in a variable. Example:

$scope.email = $window.localStorage.getItem('emailLogin');
    
16.04.2016 / 02:37