Using template-driven forms in Angular 2+, I wanted to make use of child components within a form for easier unit testing of form elements. With that said, I'd like to be able to disable the submit button with template reference variables (ie) button [disabled]="!myForm.form.valid"
. I know something should be passed from the parent-form to the child-component, but I haven't been able to figure what that is, or the syntax that should be used.
Using a Stackblitz example, How would I get the submit button disabled if the input validators (specifically minlength
in this example) are within a child component to a form?
Stackblitz Example https://stackblitz.com/edit/angular-zzeton
I've looked at the following links but they have more todo with true input-control-customization vs accessing template-reference-variables:
How to add validation in template driven form from component in angular 6 https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html#demos