This might be a stupid question with a very simple answer, but after a week of coding I feel fried and can't figure it out.
How can I bind to the Id of a selection, but display the string representation of the value? I.e., I have a drop-down that display the names of Customers, but I want to save the Id
for DB purposes.
My selection item has two properties: customer.Display
(Name), and customer.Id
.
How can I do the binding to save my Id to [(ngModel)]="loadDataService.selectedLoad.CustomerId
, but display my Display in the drop-down (it already displays the Display, so that is covered):
<mat-form-field>
<input type="text" placeholder="Customer Search" id="CustomerId" name="CustomerId" aria-label="Number" matInput [formControl]="myCustomerSearchControl"
[matAutocomplete]="auto" [(ngModel)]="loadDataService.selectedLoad.CustomerId" (keyup)="onCustomerSearch($event)">
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
<mat-option *ngFor="let customer of customerArray" [value]="customer.Display">
{{ customer.Display }}
</mat-option>
</mat-autocomplete>
</mat-form-field>