Hi guys, was trying to return an array of ids in the ion-checkbox but no avail.
These are my current code.
survey.ts
this.surveyForm = this.formBuilder.group({
questions: formBuilder.array([])
})
let question = formBuilder.group({
question_id: [this.questions[i].id, Validators.required],
answer_ids: formBuilder.array([
])
});
this.surveyForm.controls['questions'].push(question);
for (var j = 0; j < this.questions[i].answers.length; j++) {
let answer = formBuilder.array(this.questions[i].answers)
// this.surveyForm.controls['questions'].push()
};
console.log(this.surveyForm.controls.questions)
survey.html
<ion-list formArrayName="answer_ids">
<div *ngFor="let choice of question.answers; let j = index">
<ion-item>
<ion-label style="white-space: normal;">{{ choice.id }}</ion-label>
<ion-checkbox (ionChange)="onChange(choice.id, $event._checked)" value="choice.id"></ion-checkbox>
</ion-item>
</div>
</ion-list>
My current goal is to get that “answer_ids”: [81,82,83] for checked checkbox. Btw the questions are in nested form, probably there must be a way to segregate the answers control between question_id.