liveBook · Manning

Errors property

As explained in Pro Angular 16

The errors property is an Angular form-control property that contains details of the validation failures currently affecting the control.

The errors property is a nullable ValidationErrors object on an Angular form-control validation state. Its properties correspond to validation attributes that currently fail, such as required, minlength, or pattern. section 13.4.2

Access it through a template reference variable assigned to ngModel. Each error entry provides details about the failed check, while the entry’s existence can control validation-message visibility. section 13.4.2

Displaying a required-field message

Use #name="ngModel" on the input, show the message list when name.dirty && name.invalid, and test the failure with *ngIf="name.errors?.['required']". For minlength, read name.errors?.['minlength'].requiredLength to avoid duplicating the configured limit.

How Pro Angular 16 covers it

How deep it goes
Explains nullable error entries, validator-specific details, and template access, but does not cover custom-validation internals.
Examples
Uses required, minlength, and pattern checks to render conditional product-name messages.
What it assumes
Assumes familiarity with Angular templates, ngModel, validation attributes, and conditional rendering.
What you can do after
Apply it via Angular templates to select failed validators and display specific feedback.
How it connects
Connects template reference variables, ngModel, validation attributes, ValidationErrors, and ngIf.

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.