I use mat-autocomplete
and there is a feature called [displayWith]
that is used to format the value and some usefulness as far as I see. In this scene, I have the following questions:
1. What is [displayWith]
exactly used for? Can it be used to check the type of the text in the autocomplete even if the user enters a free text rather than selecting an option? Or clear the input if none of the option is selected?
2. I want to call a method in as shown below in order to check if the value is selected or not, but it does not work. So, can I call the method according to the type of the text?
I use similar approach to that:
<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));
}