23

Is there a way to set a formGroup to invalid state manually?

I tried myForm.invalid = true; and also myForm.status = 'INVALID'

But invalid and status are const.

I dont want to mark a specific control as invalid. But the whole form.

AngularDebutant
  • 1,145
  • 4
  • 13
  • 31

2 Answers2

45

Try this:

myForm.setErrors({ 'invalid': true });
tltjr
  • 1,147
  • 1
  • 15
  • 14
2

Try this formData.form.controls['email'].setErrors({'incorrect': true});

Abhishek Kumar
  • 559
  • 7
  • 15