如何使ngMessage为必填字段只显示在脏或提交表单? [英] How to make ngMessage for required fields only show when dirty or submitting a form?
问题描述
我使用AngularJS 1.3.0 RC0和角度的消息。 NG的消息尽职尽责地显示错误消息的必需的字段时,窗体最初加载和质朴。因此,新加载的表单页面与错误信息填满。这不是我想要的。如何使ngMessage为必填字段只显示在这些字段脏或提交表单?
I'm using AngularJS 1.3.0 RC0 and angular-messages. ng-messages dutifully shows error messages for those "required" fields when a form is initially loaded and pristine. So the newly loaded form page is filled up with error messages. This is not what I want. How to make ngMessage for required fields only show when those fields are dirty or submitting a form?
我看了官方文档,没有任何线索。并试图把NG秀=字段名。$脏的NG-DIV的消息,没有工作。任何帮助将是非常美联社preciated!
I have read the official doc, no clue. And tried to put "ng-show = "fieldName.$dirty"" in the ng-messages div, did not work. Any help would be highly appreciated!
推荐答案
使用 NG-如果
属性检查 $脏
上有标记 NG的消息
。
Use the ng-if
attribute to check for $dirty
on the tag that has ng-messages
.
例如:
<div ng-messages='myForm.myControl.$error' ng-if='myForm.myControl.$dirty'>
<div ng-message='required'>Required field</div>
</div>
这篇关于如何使ngMessage为必填字段只显示在脏或提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!