2016-10-22 31 views
0

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="[email protected]" 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> 

回答

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

你基本上是說輸入是ng-disabled當表單是$invalid。即在這裏您將輸入設置爲$invalid,這會使輸入被禁用。

+0

你能找到一些描述這個setvalidity的文檔嗎? –

+0

看看這個鏈接,它提供了很多$ setValidity的例子。 http://ng-learn.org/2014/03/Writing_Custom_Validations_Part4/ – Thalaivar

+0

而這個鏈接也是... http://blog.thoughtram.io/angularjs/2015/01/11/exploring-angular-1.3-validators- pipeline.html – Thalaivar