Email is not appearing in the field due in Angular

Asked

Viewed 104 times

0

Good afternoon, everyone,

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');
}
})

HTML from login screen

<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 localStorage, as shown in the image inserir a descrição da imagem aqui

  • Friend, could show the html of the login screen?

  • @Paulogustavo, just updated the post, take a look.

  • have you tried in firefox? Is it not Chrome that is overwriting with saved auto-fill?

  • I just tested in firefox and the same happens.

  • Gustavo, can you do a test? On top of the email boot {{usuario}} and see what comes out

  • Also put in various parts of html this: {{id}}. It seems to me that the problem is in HTML. Note that you open the <ion-list> tag on top of the div that contains your controllers, but close the <ion-list> in the wrong place. The div you have with loginCtrl is not being closed. You can also check this?

  • Look @Paulogustavo, I did what you suggested and nothing happened. But really, the controller div wasn’t closed and closed now. The funny thing is that before it worked! I just changed the wheel so that the user is played into the app after registering and nothing else. And as I have already commented, if I give a refresh on the screen the email, then, appears!

  • Without giving the refresh, is everything okay? Did you put {{user}} somewhere inside Ctrl to see what it looked like? I don’t know how Ionic manages localstorage, but in one of these, the solution is to save in Sesssion Storage

  • No no, on the contrary, if I give refreash on the screen, then yes the email appears. Yes, I put {{user}} just above the email field and below the controller and nothing happened.

  • @Paulogustavo, I was doing the test the wrong way. Pus {{usuario}} and appeared the email.

Show 5 more comments

1 answer

-1

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

$scope.email = $window.localStorage.getItem('emailLogin');
  • This was done, is the first stage of the controller loginCtrl

Browser other questions tagged

You are not signed in. Login or sign up in order to post.