angular - 角度反应形式模式不起作用
问题描述
我在 Angular 上使用 Reactive Form 可以同时使用数字和逗号。我制作了输入类型文本,以便点和逗号出现在移动视图的键盘上。我希望输入的输入只接受数字,但我输入的模式没有帮助。这样做后我仍然可以输入字符,但我不希望这种情况发生。
textInput: new FormControl('',
[
Validators.required,
Validators.pattern('[0-9]{7}')
]),
<input autoComplete="off" autoCorrect="off"
type="text"
lang="en"
[formControl]="this.config.textInput"
placeholder="0.0"
minLength={1}
maxLength={79}
spellCheck="false"
(ngModelChange)="amountChanged($event)"
enterkeyhint="next"
step="1"
class="w-100"
>
如何使类型为文本并且只接受数字?
解决方案
您可以使用输入类型:数字 ,例如:
<input autoComplete="off" autoCorrect="off"
type="number"
lang="en"
[formControl]="this.config.textInput"
placeholder="0.0"
minLength={1}
maxLength={79}
spellCheck="false"
(ngModelChange)="amountChanged($event)"
enterkeyhint="next"
step="1"
class="w-100">
推荐阅读
- datatable - 如何将条形码从 HTML 导出到 XLSX
- powershell - 用于从文件夹创建 TXT 文件的 Powershell 脚本
- matlab - Matlab:极坐标中的Streamslice问题
- javascript - ``在javascript中的替代品?
- c++ - '{' token 之前不允许函数定义"
- mysql - 将 COUNT 与 HAVING 一起使用但行实际存在时为 0 个结果 - MySQL
- php - PHP中的Curl Post Response未显示完整的html
- android - RecyclerView 上的 Android EditText 搜索问题
- azure-keyvault - KeyVault 架构 - 只有用户可以访问自己的数据
- python - 如何删除熊猫数据框中的某些行值(不为空)