I would like to get a value from a database and set it as a default value in an autocomplete input box.
populate clientTypes
clientTypes: any[] = [];
getClientTypes() {
this.clientService.getClientTypes()
.subscribe((data: any) => {
this.clientTypes = [...data];
});
}
for Autocomplete DisplayWith
displayFn(object): string {
console.log(object.ClientTypeId);
return object.Name;
}
in the html
<mat-form-field appearance="outline">
<mat-label>Client Type</mat-label>
<input type="text" placeholder="Select Client Type" aria-label="Number" matInput formControlName="clienttype" [formControl]="clientTypeControl" [matAutocomplete]="auto3">
<mat-autocomplete #auto3="matAutocomplete" [displayWith]="displayFn" (optionSelected)='setClientTypeId($event.option.value)'>
<mat-option *ngFor="let clientType of clientTypes" [value]="clientType">
{{ clientType.Name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
<br>
When I use the edit, I get the saved accountTypeId from the database. My problem lies on how to place the fetched accounTypeId into the the matautocomplete as a default option selected but still get the rest of the options?
Thank you.