I am using Angular2. I have this in my master component:
<form #f="ngForm" novalidate (ngSubmit)="save()">
<child [cosField]="cosField" [f]="f"></child>
<button type="submit" [disabled]="!f.valid">Submit</button>
</form>
I have a different child component that I call from this component. The code in the child component is :
<input type="text" name="flow" [(ngModel)]="cosField.value" required #name="ngModel"/>
<div [hidden]="name.valid || (!f.submitted)"
class="error">
An error has occurred.
</div>
I want to access this local variable f in the child component. Basically for form validation. If some validation fails in the child component the message "An error has occurred" gets correctly displayed. But in the master component, f.valid still remains true and so the submit button is always enabled. However if I inline the child component into the master component itself, then everything works fine and the Submit button is disabled if the validation fails. Is there a way to split a form across multiple components, and still be able to effectively validate controls using the local variable f?