Hi I have a form in one component (without button) and I have a parent component with a button to go to the next step. I would like to know how to check if the form is valid in the parent component to be able to go to the next step.
childcomponent.html
<form
[formGroup]="form"
class="clr-row"
(ngSubmit)="formSubmit.emit()"
>
<select
formControlName="chosenYear"
required
name="years"
(click)="changeYearComponent()"
[(ngModel)]="chosenYear"
>
<option *ngFor="let year of years" [value]="year">
{{ year }}
</option>
</select>
</form>
parentcomponent.ts
@ViewChild(childComponent)
public childComponent!:childComponent;
@Input() public form: FormGroup;
test() {
if (this.form.valid) {
this.next();
}
}
parentcomponent.html
<button
type="submit"
class="btn btn-primary"
(click)="test()"
>
NEXT
</button>