1
votes

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

1
Please add more information about EmployeeForm, your issue, and you tried to doAlexis
I have stated the issue and updated what I was trying and what error did I get.Dev
Is it working with incorrect instead of invalid ?Alexis
Can you add the form template and the complete ts file?Antonio Esposito
Maybe the best way will be to set all your controls as invalid like this this.EmployeeForm.controls.forEach(control => control.setErrors({'invalid':true})) or setErrors({'incorrect':true}) don't remember which one the good.Alexis

1 Answers

1
votes

Finally this worked

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