我有一个使用角度材料构建的简单表单。已经提到了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>
这可能是什么问题?
答案 0 :(得分:1)
您忘了将ngMessages
注入您的应用。
angular.module('BlankApp', ['ngMaterial', 'ngMessages']);