The Angular Material documentation indicates that certain default options may be overridden using an "Injection token":
Constants
MAT_AUTOCOMPLETE_DEFAULT_OPTIONS
Injection token to be used to override the default options for
mat-autocomplete
.const MAT_AUTOCOMPLETE_DEFAULT_OPTIONS: InjectionToken<MatAutocompleteDefaultOptions>;
It looks to expose options for panel height, option height, and a few other things. However it is a little vague on how to implement. I've been referencing this SO answer and this guide and I feel I'm getting closer, but it still is not working. This is where I am presently:
import { MAT_AUTOCOMPLETE_DEFAULT_OPTIONS, MatAutocompleteDefaultOptions } from '@angular/material';
const appearance: MatAutocompleteDefaultOptions = {
// here I would like to override `AUTOCOMPLETE_OPTION_HEIGHT` and `AUTOCOMPLETE_PANEL_HEIGHT`
};
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss'],
providers: [
{
provide: MAT_AUTOCOMPLETE_DEFAULT_OPTIONS,
useValue: appearance,
},
],
export class SearchComponent { /* etc. */ }
The properties AUTOCOMPLETE_OPTION_HEIGHT
and AUTOCOMPLETE_PANEL_HEIGHT
do not seem to exist on MatAutocompleteDefaultOptions
interface, so this must be incorrect.
The documentation specifies that "Injection Tokens" must be used, but neither the examples I've seen, nor the Material documentation itself resembles the Angular documentation on InjectionToken. Is putting it in the providers
array in some way related to injection tokens? It is very vague.
Within their Constants
section, many Material components indicate this type of behavior is attainable, so: