I´m starting to use Material in one of my projects.
Seeing the example of the <mat-autocomplete>
of the documentation website...
<mat-form-field class="example-full-width">
<input matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let state of filteredStates | async" [value]="state.name">
<span>{{state.name}}</span> |
</mat-option>
</mat-autocomplete>
ts:
export class AutocompleteOverviewExample {
stateCtrl = new FormControl();
filteredStates: Observable<State[]>;
states: State[] = [
{ name: 'Arkansas' },
...
{ name: 'Texas' }
];
constructor() {
this.filteredStates = this.stateCtrl.valueChanges
.pipe(
startWith(''),
map(state => state ? this._filterStates(state) : this.states.slice())
);
}
private _filterStates(value: string): State[] {
const filterValue = value.toLowerCase();
return this.states.filter(state => state.name.toLowerCase().indexOf(filterValue) === 0);
// Material example, its basically a ._http.get(value).map
}
}
The <mat-option>
list its deployed when you click in the input field. I would like to avoid that and only show the options when X (they have write 3 or more characters, its a 'small' list with 5 or 10 elements, etc).
How can I modify this behavior and do it dynamically?