Recently, I posted a question regarding the dynamic generation of form controllers. However, I encountered some challenges with generating templates and controllers dynamically.
In this particular project, my main focus lies on handling four types of questions stored in an array. It is crucial to dynamically generate these questions based on their respective types:
Multiple Choice Questions (MCQ) - Only one selection allowed
Multiple Select Questions - Users can choose multiple answers with at least one required
Ranking Questions - Users need to specify the correct order of answers, ensuring uniqueness
Descriptive Questions - Allows users to provide their own answers
Below is the snippet of my HTML code:
<div class="container">
<div class="row">
...
</div>
</div>
Additionally, here is my TypeScript code:
surveyQuestionForm: FormGroup;
formSubmitted = false;
constructor(private fb: FormBuilder) { }
questions: any = [
...
];
ngOnInit() {
this.createForms();
}
createForms(): any {
...
}
private buildSubGroup(question) {
...
}
atLeastOneRequired() {
...
}
uniqueNumbersValidator() {
...
}
onSubmit() {
this.formSubmitted = true;
console.log(this.formSubmitted);
}
I've observed an error message stating "control.registerOnChange is not a function." You can access the StackBlitz link for more details: https://stackblitz.com/edit/angular-nya7l9
Your guidance and assistance in resolving this issue would be highly appreciated. Thank you!