AngularJS form validation issues

Sumit picture Sumit · Jul 20, 2015 · Viewed 15.3k times · Source

I am trying to do a simple form validation using angular js. But it doesnt seems to work and I am not getting what I am missing.

HTML

Now the issue is, I am expecting that if I start entering invalid email then it will show me error message "Email Invalid". But that doesn't happen.

Also when i put a debug before submitting blank form, it says "registerForm.$valid = true"

Any guess what am I missing. Any module that i need to include ?

Here is Plunker

Answer

NeoWang picture NeoWang · Jul 20, 2015

First, you need registerForm.email.$error.email to trigger the 'invalid email' alert.

Second, I guess you have to bind these input fields with ng-models, but I am not sure if this is necessary.

One more thing, add 'novalidate' to the form element.

 <div class="form-group">
      <input class="form-control" placeholder="E-Mail" name="email" type="email" value="" ng-model="" >
      <div ng-show="registerForm.email.$error.email">Email Invalid</div>
 </div>