Here is a JSON object that I need to create a reactive form based on. What steps should I take for the array portion specifically?
{
"examName" : "java",
"password" : "1234.com",
"examCategory" : {
"id" : 78
},
"examDetailSet" :
[
{
"questionCategory" : {"id" : 40},
"section" : {"id" : 7},
"numberOfQuestions" : 3
},
{
"questionCategory" : {"id" : 41},
"section" : {"id" : 8},
"numberOfQuestions" : 6
}
],
"expiryHours" : 6
}
abc.component.ts
// The formGroup I have created
formdata = this.fb.group({
examName: ['', Validators.required], password: ['', [Validators.required, Validators.minLength(3)]],
examCategory: this.fb.group({
id: [0, Validators.required]
}),
examDetailSet: new FormArray([
new FormGroup({
questionCategory: this.fb.group({
id: [0, Validators.required]
}),
section: this.fb.group({
id: [0, Validators.required]
}),
numberOfQuestions: new FormControl(['', Validators.required])
})
]),
expiryHours: [0, Validators.required]
});
abc.component.html
<form [formGroup]="formdata" (submit)="onSubmit()">
<mat-dialog-content>
<div class="row">
<div class="col-md-6">
...
// Truncated for brevity
-pasted image link not available-
<p>I followed the instructions provided in the answer below but now I am encountering an issue stating that it can't locate the control within the <code>examDetailSet
and its controls. Any assistance would be appreciated.