ng-message不适用于选择框

时间:2016-06-23 10:48:06

标签: angularjs angular-material ng-messages

我有一个材料设计选择,我尝试使用ng-message

进行验证
<md-input-container class="md-block" flex-gt-sm >
   <label>Payment method</label>
   <md-select name="paymentMethod"  ng-model="payment.paymentMethod" flex ng-change="paymentMethodChange(payment.paymentMethod)">
      <md-optgroup label="Payment Method">
      <md-option ng-repeat="item in PayArr track by $index" value="{{item}}">{{item}}</md-option>
   </md-select>
   <div ng-messages="editForm.paymentMethod.$error" >
      <div ng-message="required">payment method required</div>
   </div>
</md-input-container>

我的表单名称是 editForm 。我对输入框使用相同的场景,它工作正常。我无法弄清楚为什么它对选择框不起作用。谢谢你们的支持

1 个答案:

答案 0 :(得分:2)

您没有将required属性放在md-select

<md-select name="paymentMethod" required  ng-model="payment.paymentMethod" flex ng-change="paymentMethodChange(payment.paymentMethod)">
      <md-optgroup label="Payment Method">
      <md-option ng-repeat="item in PayArr track by $index" value="{{item}}">{{item}}</md-option>
   </md-select>