嗨,我有这张表格要注册,由于某种原因,当我输入以.com结尾的电子邮件时,该值未传递到scope变量。

验证来自刚刚适应我需要的其他来源。

register.html

<a class="navbar" href="#/welcome" style="color: #000000;"> <<< Home</a>

<div class="intro-header fadein">
    <div class="container">
        <div class="row">
            <div class="col-lg-4">
                <div class="page-header" >
                    <h1 style="color: black; text-align: left">Register</h1>
                </div>
                <form name="register_form" novalidate ng-submit="register()">
                    <div class="input-group">
                        <input type="email"
                               name="email"
                               class="form-control"
                               placeholder="Email"
                               ng-model="user.email"
                               ng-maxlength=20
                               required/>
                        <div class="error fadein"
                             ng-show="register_form.email.$dirty && register_form.email.$invalid">
                            <small class="error fadein"
                                   ng-show="register_form.email.$error.required" style="color: black">
                                Your email is required.
                            </small>
                            <small class="error fadein"
                                   ng-show="register_form.email.$error.email" style="color: black">
                                Please input a valid email.
                            </small>
                        </div>
                    </div>
                    <div class="input-group">
                        <input type="text"
                               name="username"
                               class="form-control"
                               placeholder="Username"
                               ng-model="user.username"
                               ng-minlength=3
                               ng-maxlength=20
                               ensure-unique="username"
                               required
                               />
                        <div class="error fadein"
                             ng-show="register_form.username.$dirty && register_form.username.$invalid">
                            <small class="error fadein"
                                   ng-show="register_form.username.$error.required" style="color: black">
                                Your username is required.
                            </small>
                            <small class="error fadein"
                                   ng-show="register_form.username.$error.minlength" style="color: black">
                                Must be at least 3 characters
                            </small>
                            <small class="error"
                                   ng-show="register_form.username.$error.maxlength" style="color: black">
                                Maximum 20 characters
                            </small>
                            <small class="error fadein"
                                   ng-show="register_form.username.$error.unique" style="color: black">
                                This username is taken.</br>
                                Please choose another one.
                            </small>
                        </div>
                    </div>
                    <div class="input-group">
                        <input type="password"
                               name="password"
                               class="form-control"
                               placeholder="Password"
                               ng-model="user.password"
                               ng-minlength="8"
                               ng-maxlength="20"
                               required>
                        <div class="error fadein"
                             ng-show="register_form.password.$dirty && register_form.password.$invalid">
                            <small class="error fadein"
                                   ng-show="register_form.password.$error.required" style="color: black">
                                Your password is required.
                            </small>
                            <small class="error fadein"
                                   ng-show="register_form.password.$error.minlength" style="color: black">
                                Must be at least 8 characters
                            </small>
                            <small class="error fadein"
                                   ng-show="register_form.password.$error.maxlength" style="color: black;">
                               Maximum 20 characters
                            </small>

                        </div>
                    </div>
                    <input type="submit" class="btn btn-default" id="register_button" value="Register">
                </form>

            </div>

        </div>
    </div>
    <!-- /.container -->
</div>


authCtrl.js

angular.module('theNotesApp')
    .controller('authCtrl',['$scope', '$state', 'Auth',  function($scope, $state, Auth) {
        $scope.login = function() {
            Auth.login($scope.user).then(function () {
                $state.go('home');
            });
        };
        $scope.register = function() {
            console.log($scope.user);
            Auth.register($scope.user).then(function () {
                $state.go('home');
            });
        };
    }])




我是Web开发的新手。欢迎对代码进行改进建议。

最佳答案

您在输入字段中输入了ng-maxlength,其类型为'email',为20。您在提供的示例中使用的电子邮件地址长度为21个字符,因此该地址无效,Angular不会将其分配给user.email

增加ng-maxlength或更好的选择是完全摆脱它。

07-28 07:59