User
User

Reputation: 211

AngularJS Form Validation ($invalid, $error, etc.)

For the following code:

userType: <input name="input" ng-model="userType" required> 
...
myForm.input.$valid = {{myForm.input.$valid}}
myForm.input.$error = {{myForm.input.$error}}

Both $valid and $error will be false if the user touched the input and left it empty.

My question is:

  1. How does angularjs define $valid and $error? For example, $touched has two states (touched or untouched). but what does it mean by "valid" or "invalid"?
  2. Can I customize or redefine them?

Upvotes: 0

Views: 1061

Answers (1)

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41387

$valid simply return a boolean value depending on input is valid or not. But $error provide detail information about the errors. For eg, if you couple of validations setup for a form and all of them are invalid, then the error will show the details description of all the errors.

Demo

Upvotes: 2

Related Questions