I am making a site where I can create exams with multiple choice questions. I have a html page in which I can add questions to an exam.
A question consists out of the description of the question and multiple options. An option contains the response and a value to check if the response is true or false.
The user should be able to add options to the question when filling in the form. I am trying to use formbuilder, formgroup and formarray for this but it is not working. When I press add option, a new response and a new valid field should appear.

The fields are appearing on my html page, but I get this error when filling in the form. "Cannot find control with name response" +"cannot find control with name valid"
This is the HTML page:
<form [formGroup]="questionForm" (ngSubmit)="onSubmit(questionForm.value)">
<div>
<label>Description:</label>
<br />
<input class="form-control" id="description" type="text" formControlName="description">
<br />
<label>Options</label>
<div *ngFor="let test of arrayOptions; let i = index">
<div class=mx-4>
<label>Response</label>
<input class="form-control" id="response" type="text" formControlName="response">
<label>Valid</label>
<input class="form-control" id="valid" type="text" formControlName="valid">
</div>
</div>
<button type="button" class="btn-block-option text-primary" (click)="addOption()">
<i class="fa fa-plus" aria-hidden="true"></i>Add option
</button>
</div>
<div class="block-content block-content-full block-content-sm bg-body-light font-size-sm">
<button class="btn btn-primary" type="submit">Add</button>
</div>
</form>
This is my ts page:
export class AddQuestionComponent implements OnInit {
questionForm;
arrayOptions;
constructor(
private examSimulatorService: ExamSimulatorService,
private formBuilder: FormBuilder
) {
this.questionForm = this.formBuilder.group({
description: '',
options: ''
})
}
removeOption(i) {
this.questionForm.removeControl(i);
}
addOption() {
this.questionForm.addControl(this.questionForm.controls.options.value,
this.formBuilder.array([this.formBuilder.group(
{
response: "",
valid: ""
}
)]));
this.arrayOptions.push(this.questionForm.controls.options.value);
}
onSubmit(questionData) {
this.examSimulatorService.addQuestion(questionData);
this.questionForm.reset();
}
ngOnInit() {
this.arrayOptions = [];
this.addOption();
}
}