0
votes

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.

1
Can you post the code in the form of text? - Prashant Pimpale
For my Question quality, I put it in Pastebin. - Sivaramakrishnan
@Sivaramakrishnan, always you create a form in ngOnInit, it's usefull write the form like <form *ngIf="myForm" [formGroup]="myForm"...>. These *ngIf avoid initial errors - Eliseo

1 Answers

0
votes

I think you access myFrom before initializing it. You didn't post your code in your question, but I guess you defined validEmail in your class level and in that time your form is not initialized yet