I cannot seem to avoid the need to generate dynamic sub forms in the application I am working on. The sub form is working as expected and the sub form shows $invalid=true when one or more of it's inputs are invalid. The parent form however has $invalid=false.
I have seen people achieve nested forms where invalid sub forms invalidate the parent form, but I can't seem to do it dynamically without wrapping the dynamic compiling of the sub form in a $timeout.
In the above link I have recreated the scenario. I have three forms. The parent form, a sub form created at the same time as the parent form, and a dynamically created sub form.
If you clear the bottom existing sub form's input, it will invalidate the parent form (parent form turns red).
If you clear the top dynamic form's input, it will not invalidate the parent form (parent form remains green).
It will begin to work if you stick the addForm method in a $timeout:
// WORKS! : When you delete the dynamic added sub form input
// the parent form also becomes invalid
//timeout(addForm,0);
// FAILS! : When you delete the dynamic added sub form input text
// the parent form does NOT become invalid
addForm();
It's great that I have a workaround, but I would like to understand why I need the $timeout and if there is a solution that avoids the use of a $timeout.