Angular.js形式无效 - 不知道为什么

时间:2014-12-03 18:05:52

标签: angularjs

我不知道为什么,但是默认情况下,Angular.js中的dafault无效(表单上没有互动):

  <!-- Persistence -->
  <div class="col-sm-6" ng-class="{'has-error': form.persistence.$dirty && form.persistence.$invalid}">
    <div class="checkbox">
      <input for="persistence" type="checkbox"  ng-change="resetPersistenceInputBox(form, vip)" ng-model="persistanceCheckbox" ng-init="persistanceCheckbox=false">Client IP Based Persistence
      <div>
        <label class="control-label" style="font-weight: bold">Enter CIDR Netmask</label>
          <div class="input-group">
            <span class="input-group-addon">
              x.x.x.x/
          </span>
          <input type="text" class="col-sm-6 form-control" id="persistence" ng-init="persistanceCheckbox=false" name="persistence"
           ng-disabled="!persistanceCheckbox"
           ng-required="persistanceCheckbox"
           ng-model="vip.algorithm.persistence"
           ng-pattern='/^([0-9]|[12]\d|3[0-2])$/'
           ng-trim="true"
           placeholder="Enter a netmask between 0-32">
      </div>
      <div class="help-block" ng-show="form.persistence.$dirty && form.persistence.$invalid">
        <span ng-show="form.persistence.$error.pattern && form.persistence.$dirty">Netmask must be a number between 0-32.</span>
        <span ng-show="form.persistence.$error.required">CIDR Netmask is required while "Client IP Based Persistence" is checked.</span>
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

在您输入输入

之前,您的表单无效
 <input type="text" class="col-sm-6 form-control" id="persistence" ng-init="persistanceCheckbox=false" name="persistence"
           ng-disabled="!persistanceCheckbox"
           ng-required="persistanceCheckbox"
           ng-model="vip.algorithm.persistence"
           ng-pattern='/^([0-9]|[12]\d|3[0-2])$/'
           ng-trim="true"
           placeholder="Enter a netmask between 0-32">

ng-required="persistanceCheckbox"需要输入 并且必须符合ng-pattern:ng-pattern='/^([0-9]|[12]\d|3[0-2])$/'