coder
coder

Reputation: 357

Print the minimum length of Validator for Reactive Form

How can I get the min length value in the form?

<div *ngIf="dataForm.get('description').hasError('minlength') && dataForm.get('description').touched">
   The product description minimum length is {{ dataForm.controls.description.minlength }}.
</div>

I tried dataForm.controls.description.minlength and it prints nothing.

Upvotes: 1

Views: 83

Answers (1)

JB Nizet
JB Nizet

Reputation: 691685

dataForm.get('description').getError('minlength').requiredLength

Shameless plug: I would strongly advise avoiding to hardcode and repeat all these checks in your forms and use ngx-valdemort instead.

Upvotes: 2

Related Questions