1
votes

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?

1
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 - Eliseo
@Eliseo i have only one formGroup... the errors array is null. - Omtechguy
How do you set the validators/errors? - AJT82
@Alex Inside the formgroup ctor - Omtechguy
Could you show your code for that for clarification? :) - AJT82

1 Answers

1
votes

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>