I am current using ngFor in order to generate the checkbox HTML. However when using this method I am unable to assign a specific template reference variable to the other checkbox only in order to show/hide the textarea based off if the checkbox is checked or not.
I have tried to assign a template reference variable via the data array however that does not seem to work. I have also tried to create the checkboxes manually on the page, which then allows me to add the template reference variable however I dont seem to get the required values back from the checkboxes once thats done.
<ul formArrayName="health_care_goals">
<li class="form-group" *ngFor="let goal of health_care_goals; let i = index" formGroupName="{{i}}">
<input id="{{goal.id}}" type="checkbox" formControlName="{{goal.id}}">
<label for="{{goal.id}}"><span></span>{{goal.name == 'Other' ? 'Other (Provide details here)' : goal.name}}</label>
</li>
</ul>
<textarea *ngIf="health_care_goals_other" formControlName="health_care_goals_response_other"></textarea>
for (let i = 0; i < this.health_care_goals.length; i++) {
let fg = new FormGroup({});
fg.addControl(this.health_care_goals[i].id, new FormControl('', Validators.required));
all_health_care_goals.push(fg);
}
this.goalsForm = this._formBuilder.group({
health_care_goals: all_health_care_goals,
health_care_goals_response_other: [''],
medication_goal_reduce_harm: medication_goal_reduce_harm_strategies,
reduce_harm_from_effects_of_med: [''],
reduce_harm_from_effects_of_med_text: [''],
reducing_harms_other: ['']
});
private health_care_goals = [
{name: 'Prolonging life', id: 'prolonging_life'},
{name: 'Optimising functional independence', id: 'optimising_functional_independence'},
{name: 'Optimising quality of life', id: 'optimising_quality_of_life'},
{name: 'Achieving a peaceful death', id: 'achieving_a_peaceful_death'},
{name: 'Symptom control', id: 'symptom_control'},
{name: 'Maintaining good health and preventing illness', id: 'maintaining_good_health_and_preventing_illness'},
{name: 'Other', id: 'other'}
];
I would like to only show the textarea when the other checkbox is selected.