I am trying to check the validity of a form placed on a child component from a parent component. The best scenario would be to disable a button on the parent component if th
Since Angular applies ngForm
to all form
elements implicitly and you can reference any component/directive in the component template by component/directive class reference, you don't have to read ElementRef
and don't need the template reference #candiateForm
, you can access the form directly by the directive class reference ngForm
:
export class RightPanelComponent implements OnChanges , OnInit{
@ViewChild(NgForm) form;
checkFormValidity():boolean {
return this.form.valid;
}
And also you can access the form directly from the parent component:
export class CandidateVerificationComponent implements OnChanges, OnInit {
@ViewChild(RightPanelComponent) rightPanelPointer: RightPanelComponent;
saveAndFinish() {
if (this.rightPanelPointer.form.valid)