diff --git a/dmp-frontend/src/common/forms/reactive-asterisk-directive.ts b/dmp-frontend/src/common/forms/reactive-asterisk-directive.ts index 0b253f4d3..8aff7f8db 100644 --- a/dmp-frontend/src/common/forms/reactive-asterisk-directive.ts +++ b/dmp-frontend/src/common/forms/reactive-asterisk-directive.ts @@ -1,4 +1,4 @@ -import { AfterContentChecked, Directive } from "@angular/core"; +import { AfterContentChecked, Directive, Optional } from "@angular/core"; import { AbstractControl } from "@angular/forms"; import { MatFormField } from "@angular/material/form-field"; import { MatInput } from "@angular/material/input"; @@ -15,9 +15,10 @@ import { MarkedValidatorFn } from "./validation/custom-validator"; }) export class ReactiveAsteriskDirective implements AfterContentChecked { private readonly requiredValidatornames = ['RequiredWithVisibilityRulesValidator', 'required']; - constructor(private matFormField: MatFormField) { } + constructor(@Optional() private matFormField: MatFormField) { } ngAfterContentChecked() { + if (!this.matFormField) return; const ctrl = this.matFormField._control; const abstractControl = ctrl?.ngControl?.control; const validators = (abstractControl as AbstractControl & { _rawValidators: MarkedValidatorFn[] })?._rawValidators;