The invalid property reports whether a form control or entire form currently fails one or more validation rules. It is true when the value is invalid and false when it satisfies the applied validators. section 13.4.2 section 13.4.3
Use invalid to control validation feedback and submission behavior:
- Display field-level messages with a condition such as name.dirty && name.invalid, avoiding immediate errors before the user edits a field. section 13.4.2
- Check form.invalid after submission to determine whether any contained control has validation errors. section 13.4.3
- Combine invalid with errors to identify which validator failed, such as required, minlength, or pattern. section 13.4.2
Show a validation summary after submission
A template can display a form-wide message with *ngIf="formSubmitted && form.invalid". The submit handler sets formSubmitted, checks form.valid, and resets the form only when validation succeeds. section 13.4.3
Table 13.6. The validation object properties
|
Name
|
Description
|
|
path
|
This property returns the name of the element.
|
|
valid
|
This property returns
true
if the element’s contents are valid and
false
otherwise.
|
|
invalid
|
This property returns
true
if the element’s contents are invalid and
false
otherwise.
|
|
pristine
|
This property returns
true
if the element’s contents have not been changed.
|
|
dirty
|
This property returns
true
if the element’s contents have been changed.
|
|
touched
|
This property returns
true
if the user has visited the element.
|
|
untouched
|
This property returns
true
if the user has not visited the element.
|
|
errors
|
This property returns a
ValidationErrors
object whose properties correspond to each attribute for which there is a validation error.
|
|
value
|
This property returns the
value
of the element, which is used when defining custom validation rules, as described in the “Creating Custom Form Validators” section.
|
Compare invalid with valid, pristine, dirty, touched, and errors on the validation object. section 13.4.2
