【问题标题】:AngularJS / ng-messages: don't manage to display generic error messagesAngularJS / ng-messages:不设法显示通用错误消息
【发布时间】:2015-03-12 21:05:09
【问题描述】:

这是我的 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

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

你能告诉我有什么问题吗?

问候。

【问题讨论】:

    标签: angularjs


    【解决方案1】:

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

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

    角度变更日志:https://github.com/angular/angular.js/blob/master/CHANGELOG.md#breaking-changes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-24
      • 2018-12-05
      • 2018-12-19
      • 1970-01-01
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      相关资源
      最近更新 更多