I have a strange problem when trying to validate input[type=number] in Angular 7 and hope that somebody can help.
<input class="form-control" type="number" name="entranceFee" min="0" [(ngModel)]="entranceFee" #entranceFee="ngModel" pattern="\\d+" [ngClass]="{ 'is-invalid': entranceFee.touched && entranceFee.invalid }" >
<div *ngIf="entranceFee.invalid && entranceFee.touched" class="invalid-feedback">
<div *ngIf="entranceFee.errors.pattern">Only numbers are permitted</div>
<div *ngIf="entranceFee.errors.min">Value cannot be smaller than '0'</div>
</div>
The input shall only accept numbers >= 0. But whenever I enter a number value (0-9) the form becomes invalid. Why? When I output the ngModel in the console in ngAfterViewChecked() a number value was written to the model. So how can I validate this form? Is there a bug in the validator or in my head?
The same happens when implementing this code with reactive forms and/or with input[type=text]
minis not a validation directive. It's only a standard html attribute that the browser uses to prevent you from spinning belos the minimum.