When using mat-autocomplete
, the feature [displayWith]
is utilized to format the value and provide some functionality. This raises the following questions:
1. What exactly is the purpose of [displayWith]
? Can it be used to validate the type of text entered in the autocomplete, even if the user inputs free text instead of selecting an option? Or can it be used to clear the input if no options are selected?
2. I am attempting to call a method as shown below to determine whether a value has been selected or not, but it doesn't seem to work. Is there a way to call the method based on the type of the text entered?
The code snippet below demonstrates a similar approach:
<md-autocomplete #auto="mdAutocomplete" [displayWith]="displayFn.bind(this)">
<md-option *ngFor="let state of filteredStates | async" [value]="state.id">
{{ state.name }}
</md-option>
</md-autocomplete>
displayFn = (data?: any) => {
return data ? this.sometask(data) : '';
}
sometask(data) {
console.log(typeof(data));
}