3

我有一个单选按钮组。第一个用于“孟加拉国境内”,第二个用于“孟加拉国以外”。如果我点击“孟加拉国境内”,地址字段(文本框)不需要验证,但如果我点击“孟加拉国境外”,地址字段需要验证。看我下面的代码:

<ng-form id="validateReg" name="validateReg">
  <div ng-class="{'has-error': validateReg.chkInside.$invalid}">  
     <label>
           <input type="radio" id="radioInsideBD" required value="1" ng-model="chkInside" name="chkInside" />
           Inside Bangladesh
     </label>
     <label>
           <input type="radio" id="radioOutsideBD" required value="1" ng-model="chkInside" name="chkInside" />
           Outside Bangladesh
     </label>
   </div>
   <div ng-class="{'has-error': validateReg.address.$invalid}"> 
        Address: <textarea type="text" class="form-control" ng-model="address" name="address" id="address"></textarea>
   </div>
</ng-form>
4

1 回答 1

1
 <div ng-class="{'has-error': (addressRequired ? validateReg.address.$invalid : false)}"> 
        Address: <textarea type="text" class="form-control" ng-model="address" name="address" id="address"></textarea>
   </div>

您应该addressRequired根据选择的单选按钮设置/取消设置。

如果Inside Bangladesh选中,则将其设置为falseor else true

于 2017-05-04T09:55:04.963 回答