$error is an $error object when the key is the name of the field check and the value is the actual error message
<input type="email" name="emailName" ng-model="email" required>
for this example, myForm.emailName.$error.email = true if the email address is not myForm.emailName.$error.email = true . myForm.emailName.$error.required = true if you did not add any input to the input field
you can check whether the field is correct or not directly using myForm.emailName.$valid , but the problem in your case is that they want to show the user what is an error, having two cases. so they went into the $error object to check for error is required email or invalid email
1.Email is required. 2.Invalid email address.
therefore they used the $error object. it looks like myForm.emailName:
{"$viewValue":"ss","$validators":{},"$asyncValidators":{},"$parsers":[],"$formatters":[null],"$viewChangeListeners":[],"$untouched":false,"$touched":true,"$pristine":false,"$dirty":true,"$valid":false,"$invalid":true,"$error":{"email":true},"$name":"emailName","$options":null}
I think the example provided by you explains a lot.
santhosh
source share