AngularJs $ scope.variable in function is returning undefine

0

I started to study about angular and realized that when trying to get the value of a variable inside a function its value is being returned as undefined . Only when I try to get the value does this occur, now if I try to set the value it works normally or if I leave default values already for the variable.

It does not work.

console.log($scope.Email);

It works

$scope.Email = "123";
console.log($scope.Email);

The code is as follows

<div ng-app="Login" ng-controller="FormLogin" class="form-signin bnn-login-form">

    <h1 class="h3 mb-3 font-weight-normal">{{Cool}}Login do Usuário</h1>
    <label for="inputEmail" class="sr-only">Email address</label>
    <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="" autofocus="" ng-model="Email">
    <label for="inputPassword" class="sr-only">Password</label>
    <input type="password" id="inputPassword" class="form-control" placeholder="Password" required="" ng-model="Senha">
    <div class="checkbox mb-3">
        <label>
            <input type="checkbox" value="remember-me"> Login
        </label>
    </div>
    <button ng-click="TryLogin()" class="btn btn-lg btn-primary btn-block">Entrar</button>

</div>



<script>
    var app = angular.module('Login', []);
    app.controller('FormLogin', function ($scope) {
        $scope.TryLogin = function () {
            console.log($scope.Email);
        }
    });
</script>
    
asked by anonymous 18.09.2018 / 14:37

0 answers