I've been struggling for a few days to find a good pattern for my use case. I have a very complex reactive form, full of nested components, some fields are required, some fields may appear given certain conditions, etc... and this is creating a huge problem maintaining the code. The approach I used so far it passing the formControl to the children components and populate from there, but things started getting really hard to debug given the size of the form. A must for this form is that on submit of the whole form, a validation of all the nested fields is performed, and markAsTouched any field that is required but hasn't been inserted. I have been exploring 2 approaches but none of the 2 seems to be of any help:
- Control Value Accessor: the concept is perfect, the logic is split perfectly among the children without the parent having to concern about it, but the CON is that the children controllers are not exposed and I can't markAsTouched all the sub forms to show the respective errors
- Control Container: This approach seems to be needing all of the controls to be defined at the parent level, but being a very big form, it seems really counterproductive and not really solving my problem.
I wonder if anyone has any experience with such forms and able to provide some guidance on what are the best practises in this case. I have made a very simple stackblitz with just one sub child using Control Container, unfortunately I wasn't able to make it run https://stackblitz.com/edit/angular-ivy-axbgr5