1

As known, we can add validators to specific formControl inside formGroup and we will get the validators error (true or false) by using controlname.errors.

I found that i can add validators to the FormGroup itself which is not bind directly to formControl and i thought i can find the errors of that validators by using formGroupName.errors but this property is always null.

Can someone help with that?

5
  • You can use myForm.controls('mygroup').hasError('name_of_error`') if is a groupName, or myFom.hasError('name_of_error') if is the form itself Commented Jan 31, 2018 at 10:02
  • @Eliseo i have only one formGroup... the errors array is null. Commented Jan 31, 2018 at 10:30
  • How do you set the validators/errors? Commented Jan 31, 2018 at 10:50
  • @Alex Inside the formgroup ctor Commented Jan 31, 2018 at 12:03
  • Could you show your code for that for clarification? :) Commented Jan 31, 2018 at 12:05

1 Answer 1

1

You can add validator to the form group like this:

this.form = this.formbuilder.group({
<controls declared here>
    }, {validator: <your validator>});

You can then access the errors like this:

form.errors.<your_error_name>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.