asterisk directive fix.

This commit is contained in:
Diamantis Tziotzios 2024-06-18 12:18:55 +03:00
parent f27a98e488
commit 1cbb888ee1
1 changed files with 3 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { AfterContentChecked, Directive } from "@angular/core"; import { AfterContentChecked, Directive, Optional } from "@angular/core";
import { AbstractControl } from "@angular/forms"; import { AbstractControl } from "@angular/forms";
import { MatFormField } from "@angular/material/form-field"; import { MatFormField } from "@angular/material/form-field";
import { MatInput } from "@angular/material/input"; import { MatInput } from "@angular/material/input";
@ -15,9 +15,10 @@ import { MarkedValidatorFn } from "./validation/custom-validator";
}) })
export class ReactiveAsteriskDirective implements AfterContentChecked { export class ReactiveAsteriskDirective implements AfterContentChecked {
private readonly requiredValidatornames = ['RequiredWithVisibilityRulesValidator', 'required']; private readonly requiredValidatornames = ['RequiredWithVisibilityRulesValidator', 'required'];
constructor(private matFormField: MatFormField) { } constructor(@Optional() private matFormField: MatFormField) { }
ngAfterContentChecked() { ngAfterContentChecked() {
if (!this.matFormField) return;
const ctrl = this.matFormField._control; const ctrl = this.matFormField._control;
const abstractControl = ctrl?.ngControl?.control; const abstractControl = ctrl?.ngControl?.control;
const validators = (abstractControl as AbstractControl & { _rawValidators: MarkedValidatorFn[] })?._rawValidators; const validators = (abstractControl as AbstractControl & { _rawValidators: MarkedValidatorFn[] })?._rawValidators;