logForm。$ invalid。$ setValidity这是什么意思?

时间:2016-10-22 19:54:57

标签: javascript html angularjs

https://github.com/PatrickO10/meetUp/blob/master/index.html#L73

我是这个领域的新手并且阅读一个代码。

我在这里无法理解logForm.$invalid.$setValidity。我从网上找不到任何关于它的东西。互联网上的setvalidity有两个周边,但现在没有。

此处invalid https://docs.angularjs.org/api/ng/type/form.FormController一直是setvalidity的布尔值?为什么不使用ng-disabled="logForm.$invalid"

你可以告诉我吗?感谢。

<div class="modal fade login" tabindex="-1" role="dialog" aria-labelledby="loginModelLabel" ng-controller="LoginCtrl as logCtrl">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header primary-color-dark-bg">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="loginModelLabel">Login</h4>
            </div>
            <div class="modal-body primary-bg">
                <form class="row form-horizontal" id="loginForm" ng-submit="logCtrl.login(user)" name="logForm">
                    <label for="logEmail" class="col-xs-12 col-md-6 margin-top">
                        <span class="pad-right">Enter your email</span>
                        <input type="email" id="logEmail" ng-model="user.email" class="form-control" placeholder="example@krustykrab.com" required autocomplete="email" autofocus>
                    </label>
                    <label for="logPass" class="col-xs-12 col-md-6 margin-top">
                        <span>Enter your password</span>
                        <input type="password" id="logPass" ng-model="user.password" class="form-control" placeholder="Enter your password" required>
                    </label>
                    <div class="col-xs-12 margin-top" ng-show="loginError">
                        <p class="invalidPass">Login Fail! {{loginErrMsg}}</p>
                    </div>
                    <label class="col-xs-12 margin-top">
                        <input id="submitLogin" type="submit" value="Login" ng-disabled="logForm.$invalid.$setValidity">
                    </label>
                </form>
            </div>
            <div class="modal-footer primary-color-dark-bg">
                <button type="submit" class="btn btn-primary" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

1 个答案:

答案 0 :(得分:0)

<input id="submitLogin" type="submit" value="Login" 
             ng-disabled="logForm.$invalid.$setValidity">

当表单为ng-disabled时,您基本上将输入设为$invalid。即,在这里您将输入设置为$invalid,这使得输入被禁用。