6 typescript angular-material angular angular-reactive-forms angular8
如何让 FormBuilder 要求数字?
我正在为纬度和经度编写表单构建器。在这下面,
问题:
如何解决这个问题?
'latitude': [null, [Validators.maxLength(32), Validators.min(-90), Validators.max(90)]],
Run Code Online (Sandbox Code Playgroud)
如果可能,最好在表单中进行验证,而不是输入文本框 type=number,
您可以使用输入类型编号这将阻止任何字母
<input type="number" formControlName="latitude" />
Run Code Online (Sandbox Code Playgroud)
使用 Validators.pattern 仅允许数字的另一个选项,如果您输入了无效字符,这会将控件设置为无效。
<input type="number" formControlName="latitude" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4129 次 |
| 最近记录: |