[英]Using Array in ng-model for a input of type number shows default value as 0
我有一个数字类型的输入框,其中我使用了ng-model,这是一个数组,当数组为空时,输入将值显示为0,但是当我输入一个数字时,现有的零不会被删除,并且显示以0开头的值。
Eg: Instead of 5 it shows as 05
HTML:
<input stopccp decimalpoint
type="number"
placeholder="{{'ededuction_message' | translate}} - {{ vm.singleproduct.selectedtype === 'piece' ? 'Pec' : 'Kg' }}"
ng-model="vm.total_amount[$index]"
id="field2"
>
控制器:
vm.total_amount = [];
我怎么能只显示我键入的值,而不显示零作为前缀。
在onkeydown中使用字符串替换:
onkeydown="if(this.value.length !== 0) this.value = this.value.replace('0','');"
这是替换您所有输入的0值
onkeydown="if(this.value.length !== 0) this.value = this.value.indexOf('0') == 0 ? this.value.substring(1) : this.value;"
这是替换您的特定索引值
您也可以使用以下方法进行操作
onchange="this.value=this.value*1"
这将自动将输入的值转换为数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.