我有一个带有电子邮件字段的表单。我想阻止用户提交,除非电子邮件地址存在且有效。但是,我只想在切换出电子邮件字段或单击sumbit时显示这些错误。我的"无效的电子邮件"消息在用户输入电子邮件时出现,并且在他们输入有效电子邮件之前一直显示。我该如何防止这种行为?
<div ng-show="emailMeForm.Email.$error.required" class="errorMessage">
You must enter an email
</div>
<div ng-show="emailMeForm.Email.$error.email" class="errorMessage">
Email address invalid
</div>
<form name="emailMeForm" novalidate="">
Email Address
<input ng-model="vm.emailAddress" type="email" name="Email" />
<button ng-click="emailMeForm.$valid">Continue</button>
</form>
答案 0 :(得分:1)
必须足够:
ng-show="emailMeForm.Email.$touched && emailMeForm.Email.$error.required"