ng-messages-include 指令不显示消息

ng-messages-include directive is not displaying messages

我希望有人能告诉我 ngMessages 指令做错了什么。我使用的代码是:

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


<div ng-controller="SomeController">
  <div class="row">
      <div class="col-md-6">
          <form name="profileForm" ng-submit="model.submit()" novalidate>
              <div>
                  <label for="username">Your user name:</label>
                  <input type="text" id="username" name="username" required placeholder="User name" ng-model="model.user.username">
                  <div class="help-block" ng-messages="profileForm.username.$error">
                      <div ng-messages-include="error-messages"></div>
                  </div>
              </div>
              <button>submit</button>
          </form>
      </div>
  </div>
</div>

我在这里创建了一个 plunk ng-messages-include plunk

在这里已经有好几个小时了。 谢谢

默认情况下,

ngMessages 不附带 angular。因此,当您添加 ng-messages 指令时,angular 不会编译它并且什么也不会发生。

您应该做的是将 ng-messages 添加到脚本标记并在您的应用定义中添加模块 ngMessages

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-messages.min.js"></script>

var anApp = angular.module('anApp', ['ngMessages']);

查看更新的插件:http://plnkr.co/edit/1CtamfeVCpggDApH9Enp?p=preview