Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Angular Material MAT_AUTOCOMPLETE_DEFAULT_OPTIONS injection token

What is the way to use the MAT_AUTOCOMPLETE_DEFAULT_OPTIONS injection token, or the const AUTOCOMPLETE_OPTION_HEIGHT to customize mat-autocomplete. These constants, among others are exposed in the public API here but no documentation on how to use them

like image 215
Gidon Avatar asked Oct 28 '18 09:10

Gidon


People also ask

What is matAutocomplete?

The <mat-autocomplete>, an Angular Directive, is used as a special input control with an inbuilt dropdown to show all possible matches to a custom query. This control acts as a real-time suggestion box as soon as the user types in the input area.

What is Displaywith in Mat autocomplete?

A simple way to display the selected autocomplete value in an input field.

How do you clear mat autocomplete when no option is selected from autocomplete dropdown?

You can remove the formControl-binding from your input and when you select an option you set that id to your form. You are already calling such a function (onSelectionChange)="onEnteredAccount(accountOption)" in which you can do that.


1 Answers

Add MAT_AUTOCOMPLETE_DEFAULT_OPTIONS to your module's providers array like this:

providers: [
  // ...
  {provide: MAT_AUTOCOMPLETE_DEFAULT_OPTIONS, useValue: {autoActiveFirstOption: false}}
]

As for the other constants, I'm not sure you can adjust them. You'll probably have to play around with the CSS styles, see for instance this issue for adjusting the panel height.

like image 90
Jeto Avatar answered Sep 28 '22 02:09

Jeto