An auto-complete select that show a list of options. Each option is an object. I want to show the name of each option but send it's Id. This code works. But once the option is selected, the input shows the id. I want to show the name.
Documentation suggests the use of [displayWith]="displayFn" but it require to change [value]="freespin.id" by [value]="freespin" and I don't want that.
I have not found a solution yet.
<mat-form-field>
<mat-label>Freespin</mat-label>
<input type="text"
placeholder="Select a freespin"
matInput
formControlName="freespin"
[matAutocomplete]="auto">
<mat-autocomplete requireSelection #auto="matAutocomplete">
<mat-option *ngFor="let freespin of filteredFreespins[i] | async" [value]="freespin.id">
{{freespin.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
Could you try using the
displayWithattribute, please find below a working example!html
ts
stackblitz