Patch value未将值设置为mat-select



我在表单中有一个垫子选择下拉菜单以及许多其他控件。我做补丁值后,从DB。除了mat-select,所有的东西都被映射了。

UI代码
<mat-label>Select an option</mat-label>
<mat-select formControlName="organization"  >
<mat-option [value]="0">None</mat-option>
<mat-option [value]="1">Bank Operations (Mike Conticello)</mat-option>
<mat-option [value]="2">Brokerage product Services (Kent Clark)</mat-option>
<mat-option [value]="3">Custody & Asset Services ( Staci Sullivan)</mat-option>
</mat-select>

TS代码

this.nominationSvc.GetNominationById(this.id)
.then(
result => {
if (result != null) {
console.log(result.organization);
this.nominationForm.patchValue(result);
}
}
});

由于result中的organization值为字符串,

将mat-option的值改为string

<mat-select formControlName="organization"  >
<mat-option [value]="'0'">None</mat-option>
<mat-option [value]="'1'">Bank Operations (Mike Conticello)</mat-option>
<mat-option [value]="'2'">Brokerage product Services (Kent Clark)</mat-option>
<mat-option [value]="'3'">Custody & Asset Services ( Staci Sullivan)</mat-option>
</mat-select>

最新更新