【发布时间】:2020-09-13 19:34:30
【问题描述】:
当我进入编辑表单时,我需要将值预填到表单中。
创建表单工作正常,值提交正常,
HTML:
<!-- customers-->
<div class="col-md-6">
<mat-form-field class="example-full-width">
<input type="text"
placeholder="Customers"
i18n-placeholder="customerInput"
aria-label="customers"
matInput
required
[name]="'customerId'"
(focus)="getCustomers(searchedCustomer)"
[ngModel]="contractInterface.customerName"
(ngModelChange)="customerOnChange($event)"
[matAutocomplete]="autoCustomer">
<mat-autocomplete #autoCustomer="matAutocomplete" [displayWith]="customerCollectionDisplayFn">
<mat-option *ngIf="customerloading"><span [ngTemplateOutlet]="loading"></span></mat-option>
<ng-container *ngIf="!customerloading">
<mat-option *ngFor="let customer of customerList" [value]="customer">
{{ customer.name }}
</mat-option>
</ng-container>
</mat-autocomplete>
</mat-form-field>
</div>
我使用[displayWith]="customerCollectionDisplayFn" 将值显示到输入
TS:
customerCollectionDisplayFn(customer?) {
return customer?.name;
}
【问题讨论】:
标签: angular angular-material angular2-forms angular9 ngmodel