set form manually to invalid angular 2+

AngularDebutant picture AngularDebutant · Sep 29, 2017 · Viewed 35.8k times · Source

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.

Answer

tltjr picture tltjr · May 9, 2018

Try this:

myForm.setErrors({ 'invalid': true });