I need help understanding how FormGroup, FormControl, FormArray work in Angular.
The error message I'm encountering is:
Type '{ question: FormControl; multi: true; choices: FormArray; }' is not assignable to type 'AbstractControl'.
Object literal may only specify known properties, and 'question' does not
exist in type 'AbstractControl'.ts(2322)
My attempt at using these controls:
survey: FormGroup;
results = {
success:"",
error:""
}
constructor(private fb: FormBuilder) { }
ngOnInit() {
this.survey = new FormGroup({
name: new FormControl(['My Quick Survey', Validators.required]),
questionnaires: new FormArray([{
question: new FormControl('Ready for a quick survey?'), //error
multi:true,
choices: new FormArray([
{text: new FormControl('Yes')}, //error
{text: new FormControl('No')} //error
])
}])
})
console.log(this.survey)
}
Currently, I have structured my code like this:
survey = {
name:"My Quick Survey",
questionnaires:[{
question:"Ready for a quick survey?",
multi:true,
choices:[
{text:"Yes"},
{text:"No"}
]
}]
}
I am unsure how to resolve the error. Any guidance would be appreciated.
Thank you