AngularJS / ng-messages:不设法显示通用错误消息

时间:2015-03-12 12:45:26

标签: angularjs

这是我的HTML代码:

<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

当我输入太短的字符串或什么都没有时,我没有收到任何预期的消息。

你能告诉我出了什么问题吗?

问候。

1 个答案:

答案 0 :(得分:2)

使用Angular 1.3.x版本ng-messages-include指令应与ng-messages一起在同一节点上指定

更新了plnkr:http://plnkr.co/edit/9gguHn8RF6qONR5uKQ1w?p=preview

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