As I work on validating my forms using mat-errors and hasErrors, everything runs smoothly until I encounter the need for another control within an "inner" form group. Here is what I mean:
prozessPersonenzuordnungenForm = new FormGroup({
person: new FormGroup({
firmenbezeichnung: new FormControl(),
nameC: new FormControl('', [Validators.required]),
briefanrede: new FormControl('x'),
}),
});
I am trying to access the validation for person.nameC. I am currently using this function:
public hasError = (controlName: string, errorName: string) => {
return this.prozessPersonenzuordnungenForm.controls[controlName].hasError(
errorName
);
};
The issue lies in the fact that with this function, I can only reach the person FormGroup and not the nameC formControl. Thus, I require a "deeper control."
This is how my HTML is structured:
<mat-error *ngIf="hasError('nameC', 'required')">Please enter a person!</mat-error>
I have also attempted using person.nameC in the HTML, but it did not work either. What would be a suitable approach to access my inner FormControl with the hasError function?