AngularDebutant
AngularDebutant

Reputation: 1576

set form manually to invalid angular 2+

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.

Upvotes: 28

Views: 59222

Answers (2)

Abhishek Kumar
Abhishek Kumar

Reputation: 1040

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

Upvotes: 2

tltjr
tltjr

Reputation: 1336

Try this:

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

Upvotes: 53

Related Questions