简体   繁体   中英

AngularJS / ng-messages: don't manage to display generic error messages

Here is my HTML code:

<script type="text/ng-template" id="my-custom-messages">
  <div ng-message="required">This field is required</div>
  <div ng-message="minlength">This field is too short</div>
</script>

<form name="myForm">
  <input type="email"
         id="email"
         name="myEmail"
         ng-model="email"
         minlength="5"
         required />

  <!-- any ng-message elements that appear BEFORE the ng-messages-include will
       override the messages present in the ng-messages-include template -->
  <div ng-messages="myForm.myEmail.$error">
    <!-- and here are the generic error messages -->
    <div ng-messages-include="error-messages"></div>
  </div>

Plunker: http://plnkr.co/edit/AL41PW?p=preview

When I enter a too short string or nothing, I don't get any message as expected.

Could you please tell me what's wrong ?

Regards.

With Angular 1.3.x version ng-messages-include directive should be specified on the same node along with ng-messages

Updated plnkr: http://plnkr.co/edit/9gguHn8RF6qONR5uKQ1w?p=preview

Angular changelog: https://github.com/angular/angular.js/blob/master/CHANGELOG.md#breaking-changes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM