我从后端得到了一个JSON格式的数据,在前端使用下拉选择标签时,无法预先选择与json数据匹配的选项。此外,从后端获取的数据是enum
格式,我需要相应地解析1
为男性
,2
为女性
。这是我后端数据的格式:
{
"salesPersonId": 13,
"name": "testName",
"gender": 1,
"phone1": "34986215",
"phone2": "string",
"email": "testingEmail@example.com",
"team": "Bravo",
"teamLeader": "Delta",
"countyId": 1,
"county": null,
"subCountyId": 1,
"subCounty": null,
"address": "House 108",
"additionalInfo": "He Drinks tea",
"input1": "string",
"input2": "string"
}
这里是我尝试将其与接收到的数据绑定的内容:
<mat-form-field appearance="outline" fxFlex="33" class="pr-4">
<mat-label>Gender</mat-label>
<mat-select formControlName="gender">
<mat-option value="1">1</mat-option>
<mat-option value="2">2</mat-option>
</mat-select>
</mat-form-field>
无论是没有产生任何错误,也没有预先选择来自后端的性别标签。注意:我正在使用响应式表单。谢谢。