Having an issue with selecting the gender option from JSON formatted data received from the backend. The gender is displayed as a select tag on the frontend, but it does not pre-select the option that corresponds to the gender value in the JSON data. The backend sends the gender in enum format; I need it to be parsed as '1' for 'Male' and '2' for 'Female'. Here is the structure of the backend data:
{
"salesPersonId": 13,
"name": "testName",
"gender": 1,
"phone1": "34986215",
"phone2": "string",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62160711160b0c05270f030b0e22071a">[email protected]</a>",
"team": "Bravo",
"teamLeader": "Delta",
"countyId": 1,
"county": null,
"subCountyId": 1,
"subCounty": null,
"address": "House 108",
"additionalInfo": "He Drinks tea",
"input1": "string",
"input2": "string"
}
Here is how I am trying to bind this data:
<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>
The gender is not being pre-selected based on the back-end data received, and there are no errors thrown. Note that I am using reactive forms. Thank you in advance.