Home:ALL Converter>Angular template driven form not performing min validation

Angular template driven form not performing min validation

Ask Time:2021-05-09T17:42:16         Author:Prajwal

Json Formatter

I have angular 11 template driven form with this input

<form #currentForm="ngForm">
<input matInput type="number" min="18" placeholder="Your age" name="age" [(ngModel)]="memberDetailForm.age">
</form>

{{ currentForm.controls.age?.errors | json }}
{{ currentForm.valid }}

Here form is not performing min validation check, even if I enter 15 which is less than 18, I see no errors and form shows valid. However if I change the input type to text and have some other check like minLenth="5" and enter 4 chars, the error shows up and forms become invalid.

Can anybody help me understand this strange behavior?

Author:Prajwal,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67456277/angular-template-driven-form-not-performing-min-validation
yy