I have following structure:
Parent component (dialog)
<form #dialogForm="ngForm">
<app-window-element></app-window-element>
</form>
<button (click)="button.callback(dialogForm)">Click me</button>
Child component (element)
<div>
<label for="email">Email</label>
<input type="text" name="email" id="email" formControlName="email">
<label for="password">Password</label>
<input type="password" name="password" id="password" formControlName="password">
</div>
And when click to button - send #dialogForm.
But I have problem - object dialogForm don't has fields from children-components. (dialogForm is NgForm)
And I get error:
WindowFormComponent.html:5 ERROR Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup directive and pass it an existing FormGroup instance (you can create one in your class).
Example:
<div [formGroup]="myGroup"> <input formControlName="firstName"> </div> In your class: this.myGroup = new FormGroup({ firstName: new FormControl() });
If I have just fields within form - it is works, but is is don't work with children-components.
<form #dialogForm="ngForm">
<label for="email">Email</label>
<input type="text" name="email" id="email" formControlName="email">
<label for="password">Password</label>
<input type="password" name="password" id="password" formControlName="password">
</form>
<button (click)="button.callback(dialogForm)">Click me</button>