export class FormContainerComponent implements OnInit {
private rootFormGroup = inject(FormGroupDirective);
@Input() formContainer!: FormContainer;
public formGroup!: FormGroup;
public errors?: ValidationErrors | null;
ngOnInit() {
this.formGroup = this.rootFormGroup.control;
this.errors = this.formGroup
.get(this.formContainer.formGroupName)
?.get(this.formContainer.formControlName)?.errors;
console.log(this.errors);
}
public showError(): string {
switch (this.errors) {
case Validators.maxLength: {
return 'max length error';
}
default: {
return 'no error!';
}
}
}
}
this.errors has a single error (maxLength). I want to use a function showError() to display the error in the template.
The switch is returning the "no error!" string, but "this.errors" has an error. Any suggestions what to fix?