Search code examples
htmlangularform-control

Why my validator of maxlenght is state reversed?


I m facing A mallessious issue with a simple form on my angular application.

I have the following

<mat-error *ngIf="errorControlsName.hasError('minLength') || !errorControlsName.hasError('maxLength')

                || errorControlsName.hasError('pattern')">{{ 'wsForm.errors.invalidFormat' | translate }}

            </mat-error> 

My form controll

the test result

What Is blowing my ming why the error is triggered using the negation !errorControlsName.hasError('maxLength') For me it should be errorControlsName.hasError('maxLength')

m I miss understanding something ???


Solution

  • Try using lowercase

    .hasError('maxlength')
    

    'minLength' probably only seems to work because your regex in 'pattern' already disallows it.