I am a bit confused with angular's form group and form array. I know you can nest form arrays in form groups but can a form array exists on its own? Basically I need the entire form to be an array that I can push "base" controls to, OR, insert controls at certain positions depending on selections from a dropdown. for example
- Name (text field)
- Phone (text field)
- Payment schedule (dropdown w/ values of weekly, monthly, yearly)
- Address (text field)
If weekly is selected from the payment schedule dropdown I need to show a new input, lets say its called "day of week", in between payment and address fields.
This is the part that im struggling with. I've basically built out this (https://scotch.io/tutorials/how-to-build-nested-model-driven-forms-in-angular-2)tutorial but can't wrap my head around how to add field in between each other if the whole form is not a form array, which I can't seem to do.
question-control.service.ts (from angular docs. see: https://angular.io/guide/dynamic-form)
questions.forEach(question => {
group[question.key] = question.required ?
new FormControl(question.value || '', [Validators.required, Validators.minLength(question.minLength)]) :
new FormControl(question.value || '');
});
return new FormGroup(group);