How to manually set an Angular template driven form as invalid in angular9

yotube
0

Issue

I want to manually set the EmployeeForm as Invalid from the .ts file. Here EmployeeForm is a Template driven form.

I have tried to do the following but it didn't work.

this.EmployeeForm.setErrors({ 'invalid': true }); 

error message says:

Property 'setErrors' does not exist on type 'NgForm'. Did you mean 'getError'?

The same code works when I use it with other forms which are Reactive forms


Solution

Finally this worked

this.EmployeeForm.form.setErrors({ 'invalid': true });


Answered By - Dev

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top