简体   繁体   English

防止在输入数据时进行角度验证

[英]Prevent angular validation from occurring while entering data

I have a form with an email field.我有一个带有电子邮件字段的表单。 I would like to prevent the user from submitting unless the email address exists and is valid.我想阻止用户提交,除非电子邮件地址存在且有效。 However, I only want these errors to appear when toggling out of the email field or clicking sumbit.但是,我只希望在切换出电子邮件字段或单击 sumbit 时出现这些错误。 My "invalid email" message is appearing WHILE the user is typing the email and remains visible until they've finished entering a valid email.我的“无效电子邮件”消息在用户输入电子邮件时出现,并且在他们输入有效电子邮件之前一直可见。 How can I prevent this behavior?我怎样才能防止这种行为?

        <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>

必须足够:

ng-show="emailMeForm.Email.$touched && emailMeForm.Email.$error.required"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM