Validation
Validates the autocomplete like any other Material form field. Bind it with formControlName, set invalid from the control (here once it is touched) to turn the label and underline red, and pass helperText — shown as a mat-hint while valid and as a mat-error, linked via aria-describedby, while invalid. required adds the label asterisk. Leave a field and press Submit to compare it with the plain mat-select beside it.
Overview
Examples
Usage
Import AutocompleteComponent and configure it with the inputs below. The full runnable source is on the Examples tab.
<autocomplete
formControlName="film"
[options]="films"
[required]="true"
[invalid]="film.invalid && film.touched"
[helperText]="film.invalid && film.touched ? 'Movie is required' : 'Start typing to search'"
label="Movie" />API
This example demonstrates the inputs below. See the Autocomplete introduction for the complete API — every input, output, content template and filter helper.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
required | boolean | false | Marks the control required (label asterisk + aria-required). |
invalid | boolean | false | Puts the field in its error state (red label/underline, aria-invalid) and shows helperText as a mat-error. |
helperText | string | null | null | Text under the field: a mat-hint normally, a mat-error while invalid (MUI helperText). |
