如何在Angular JS材料中单独引发表单错误?

时间:2018-08-29 11:48:31

标签: angularjs angularjs-material

我正在使用angularjs材质并尝试分别引发错误。我有一个简单的表格,其中有textarea,我在其中应用maxlengthrequired

    <form class="form-horizontal" enctype="multipart/form-data" name="addEditPromocodeForm" ng-submit="addEdit.addPromoCodeInPopup(addEdit.bank);">

  <md-input-container>
                     <label>PromoText</label>
                     <textarea rows="3" id="promoText" name="promoText" ng-model="addEdit.promoText"  ng-maxlength="150" required></textarea>
                            required : {{addEditPromocodeForm.promoText.$error.required}} <br>
                            max length : {{addEditPromocodeForm.promoText.$error.maxlength}}<br>
                            error : {{addEditPromocodeForm.promoText.$error | json}}
                            <div ng-messages="addEditPromocodeForm.promoText.$error" >
                                <div class="error"  ng-message="required">PromoText is required</div>
                                <div class="error"  ng-message="maxlength">PromoText is too long</div>
                            </div>
                        </md-input-container>
        </form>

但不幸的是,我每次都看到两个错误。尽管我在$error数组中清楚地看到,当特定错误到来时,$error数组仅包含该特定错误。像这样

error : { "required": true }

如果出现maxlength错误,则$error数组将变成这样

error : { "maxlength": true }

但是我仍然遇到两个错误,为什么?

0 个答案:

没有答案