如何为文本框设置最小值和最大值,以及如何测试最小值不大于最大值?
<input type="number" placeholder="User Id" required min="1" max="100" [(ngModel)]="userId" name="userId" #pickedId="ngModel">
<div *ngIf="!pickedId.valid && pickedId.touched && !newUserForm.form.valid">
User id is required!
</div>
答案 0 :(得分:0)
Angular支持validators设置表单的最小值和最大值。获取文本框并显示最小值不大于最大值?要使用验证器,请尝试以下示例...
// check for valid number and value range ie: [10-100]
var numberControl = new FormControl("", Validators.number({min: 10, max: 100}))