I tried for Angular Reactive form and my code for the component class is: Component Class file
And my HTML code is: HTML file
I get this error in console:
core.js:15724 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'controls' of undefined
TypeError: Cannot read property 'controls' of undefined
at new LoginComponent (login.component.ts:24)
I know this error is because of the line:
validEmail = {
field: true,
error: this.myForm.controls.email.invalid && this.myForm.controls.email.dirty
};
Also if I attempt to comment and 'error:' ngClass object, the condition:
!myForm.invalid
in login form submit button not working.
I am new to angular, the doc is kinda more general. So please help me how to fix it. For your testing, use the semantic-UI library for viewing the HTML.
<form *ngIf="myForm" [formGroup]="myForm"...>. These *ngIf avoid initial errors - Eliseo