AngularJS ng-model绑定问题,输入类型=电子邮件元素

时间:2017-07-16 22:36:40

标签: javascript html angularjs

我有一个奇怪的问题。 不记录电子邮件输入值,但会记录密码值。 任何想法的人?

<div class="container" ng-controller="loginCtrl">
    <div class="row" style="height: 50px;">&nbsp;</div>
    <div class="row">

        <div class="col-xs-4 col-xs-offset-4" >

            <div class="form-group">
                <label for="emailinput">Email address</label>
                <input type="email" class="form-control" id="emailinput"
                       ng-model="user.email"
                       placeholder="Enter Email Address">
            </div>
            <div class="form-group">
                <label for="passwordinput">Password</label>
                <input type="password" class="form-control" id="passwordinput"
                       ng-model="user.pass"
                       placeholder="Enter Password">
            </div>
            <div class="form-group">
                <button class="btn btn-primary ladda-button"
                        ng-click="verifyCredentials()"
                        data-style="expand-left">
                     <span class="ladda-label">Login</span>
                </button>
            </div>
            <div class="form-group">
                <label for="passwordinput">
                    <a href="forgotpassword.html">Forgot Password?</a>
                </label>
            </div>

        </div>
    </div>
</div>

我的角度代码如下。

var app = angular.module('bookie',[]);

app.controller('loginCtrl', function($scope, $http){
    $scope.user = {};
    $scope.verifyCredentials = function(){
        console.log($scope.user);
    }
});

2 个答案:

答案 0 :(得分:1)

只有在合法的电子邮件地址时才会显示该电子邮件:

&#13;
&#13;
<script src="//unpkg.com/angular/angular.js"></script>
<div ng-app ng-init="user={}">
    <div class="form-group">
        <label for="emailinput">Email address</label>
        <input type="email" class="form-control" id="emailinput"
               ng-model="user.email"
               placeholder="Enter Email Address">
    </div>
    <div class="form-group">
        <label for="passwordinput">Password</label>
        <input type="password" class="form-control" id="passwordinput"
               ng-model="user.pass"
               placeholder="Enter Password">
    </div>
    <div class="form-group">
        <button class="btn btn-primary ladda-button"
                ng-click="verifyCredentials()"
                data-style="expand-left">
             <span class="ladda-label">Login</span>
        </button>
    </div>
    <div class="form-group">
        <label for="passwordinput">
            <a href="forgotpassword.html">Forgot Password?</a>
        </label>
    </div>

     {{user | json}}
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

仅当用户输入正确的电子邮件地址(即 -something@xyz.com)时才会显示电子邮件

<label>EMAIL:</label>
<input type="email" ng-model="uemail"  name="ueamil" placeholder="Enter EMAIL">
<h4> EMAIL: {{uemail}}</h4>