输入所需的表单输入所需消息不会消失

时间:2016-10-02 13:09:44

标签: angularjs angular-material

参考this codepen link

我有一个使用角度材料构建的简单表单。已经提到了angular material demo

字段标记为必填字段,如果未输入,则显示field required消息。但是,一旦有效输入,该消息就不会消失。然而,在官方演示中,这是有效的。

这是与表单相关的HTML代码:

<form name="myform">
<md-input-container flex="50">
  <label>Name</label>
  <input required name="name" ng-model="project.name">
  <div ng-messages="myform.name.$error">
    <div ng-message="required">This is required.</div>
  </div>
 </md-input-container>
<md-input-container class="md-block">
    <label>Email</label>
    <input required type="email" name="email" ng-model="project.email"
           minlength="10" maxlength="100" ng-pattern="/^.+@.+\..+$/" />

    <div ng-messages="myform.email.$error" role="alert">
      <div ng-message-exp="['required', 'minlength', 'maxlength', 'pattern']">
        Your email must be between 10 and 100 characters long and look like an e-mail address.
      </div>
    </div>
  </md-input-container>

<md-button class="md-raised md-primary">Submit</md-button>
</form>

这可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您忘了将ngMessages注入您的应用。

angular.module('BlankApp', ['ngMaterial', 'ngMessages']);