我想从数据库中获取一个值并将其设置为自动完成输入框中的默认值。
填充客户端类型
clientTypes: any[] = [];
getClientTypes() {
this.clientService.getClientTypes()
.subscribe((data: any) => {
this.clientTypes = [...data];
});
}
用于自动完成 DisplayWith
displayFn(object): string {
console.log(object.ClientTypeId);
return object.Name;
}
在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>
当我使用编辑时,我从数据库中获取保存的 accountTypeId。我的问题在于如何将获取的 accounTypeId 作为默认选项放置到 matautocomplete 中,但仍然可以获得其余选项?
谢谢你。