My requirement was to show the selected value in the Input Box and get the Selected Id and Value to the .ts file. As I need the Id and Value I am binding the option value directly to [value]. But if I do that it's getting printed as [Object Object].
<mat-form-field appearance="outline" class="w-100">
<mat-label>Enter Hotel Name</mat-label>
<input type="text" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selectedclient($event)">
<mat-option *ngFor="let option of clients; let i = index" [value]="option">
{{ option.name }}
</mat-option>
</mat-autocomplete>
<mat-icon matSuffix>location_on</mat-icon>
</mat-form-field>
Ts File
options = [
{ id: 1, name: 'One'},
{ id: 2, name: 'Two'},
{ id: 3, name: 'Three'}
];
selectedclient(event) {
console.log(event.option.value);
}
Stackblitz Editor URL: https://stackblitz.com/edit/angular-mat-select-data-n4tvmj