对于类型为数字的输入元素,当输入的数字具有前导零(例如“0000123456”)时,模型将更新为 123456,而视图/输入仍保持相同的 0000123456。
但是,如果我从数字切换到文本,一切都会按预期进行。我想要一个数字,因为它会显示移动设备的数字键盘。
<input type="number" ng-model="vm.orderid"/>
{{vm.orderid}}
PLUNKR
正如 @Steve 所说,我使用了自定义指令my-decimals
当输入失去焦点时,它将视图值与模型相匹配。
<input type="number" my-decimals ng-model="vm.orderid"/>
angular.directive('myDecimals', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
elm.blur(function() {
var val = ctrl.$viewValue;
ctrl.$setViewValue(val * 1);
ctrl.$render();
});
}
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)