Issue
Understanding Lets say i received value "Yes" and "No". My question is i want to check the checkbox only when i received "Yes".
codes that i tried
<section class="pleft ptop" *ngFor="let item of patientPastMedicalHistoryList">
<mat-checkbox color="primary"
(change)="patientPastHistoryForm.get('substanceAbuseAlcohol').setValue(
$event.checked ? 'Yes' : 'No')"
checked="{{item.substanceAbuseAlcohol ==='Yes'}}"
>Alcohol</mat-checkbox><br>
</mat-form-field>
</section>
I have tried This doesnt help. Below code always check the checkbox even when the value received is "NO"
[checked]="patientPastHistoryForm.get('substanceAbuseAlcohol').value=='Yes'"
checked="{{item.substanceAbuseAlcohol ==='Yes'}}"
form
this.patientPastHistoryForm = new FormGroup({
patientId: new FormControl(this.clientId),
substanceAbuseAlcohol: new FormControl(''),})
data
patientPastMedicalHistoryList: Array<PatientPastMedicalHistoryModel>=[];
This is how i fetch the value
getPatientPastHistoryList() {
debugger
this.clientsService.getPatientPastHistoryList(this.clientId)
.subscribe(
(response: ResponseModel) => {
if (response.statusCode === 200) {
this.patientPastMedicalHistoryList = response.data;
} else {
this.patientPastMedicalHistoryList = [] ;
}
this.patientPastHistoryForm.patchValue({
...response.data,
})
});
}
Received data
{
"expires_in": 0,
"data": [
{
"id": 0,
"patientId": 2143,
"substanceAbuseAlcohol": "No",
"substanceAbuseMarijuana": "Yes",
}
Solution
Stackblitz
response.data is an array
you want this.patientPastHistoryForm.patchValue({ ...response.data[0], })
Answered By - Andrew Allen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.