Search code examples
angularjsangular-ngmodel

ng-model for `<input type=email` not working with ng-required


Im using AngularJS for a simple web. Im traing to cofigurate a form validation, but im having problem storing de values of the inputs in the model.

the code is this

<div class="login-form">
    {{login}}
    <form name="loginForm" action="" method="post" novalidate>

        <h2 class="text-center"></h2>
        <div class="form-group">
            <input name="username" type="text" class="form-control" placeholder="Username"
                   ng-model="login.username" ng-required="true">
        </div>
        <div class="form-group">
            <input name="password" type="password" class="form-control" placeholder="Password"
                   ng-model="login.password" ng-required="true">
        </div>
        <div class="form-group">
            <input type="submit" value="Enviar" class="btn btn-primary btn-block" />
        </div>
        <div class="clearfix">
            <label class="pull-left checkbox-inline">
                <input type="checkbox"> Recordarme</label>
            <br />
            <a href="#" class="pull-right">Olvidaste tu Contraseña?</a>
        </div>
    </form>
    <p class="text-center"><a href="#">Crear una cuenta</a></p>
</div>

If i change input type="email", for the username, the value is not stored in the object. What can i do?


Solution

  • No it's not a issue, The email will only show when it is a legal email address. so you need to have entered a valid email address before it is bound to the model.

    try with something like,

    sa@99t.com