Mat-Autocomplete-Async is a library to make building an autocomplete with Angular Material easier.
Here is an example.
-
Install the library.
npm i mat-autocomplete-async
-
Create an observable arrays for looking filtered options.
-
Using a normal angular material autocomplete templete, but adding
matAutocompleteHttp
as attribule inMatInput
<mat-form-field> <input type="text" placeholder="Pick one" matInput [formControl]="myControl" [matAutocomplete]="auto" matAutocompleteAsync > <mat-autocomplete #auto="matAutocomplete" autoActiveFirstOption="true"> <mat-option *ngFor="let option of filteredOptions | async" [value]="option.id"> {{option.name}} </mat-option> </mat-autocomplete> </mat-form-field>