gpt4 book ai didi

javascript - Angular ngModelOptions allowInvalid无法正常工作

转载 作者:行者123 更新时间:2023-12-01 03:31:29 26 4
gpt4 key购买 nike

我有这样的代码,在这里我设置选项{allowInvalid: true}

<input type="number" name="userName"
ng-model="user.name"
ng-model-options="{ allowInvalid: true }"
ng-blur="test(user)"/>

当我将非数字值输入非数字时,例如: abc
为什么 user.name仍然更改为 undefined
我期望模型 user.name应该是 'abc'

完整代码: http://plnkr.co/edit/BsLk2GWVkchNgKaOV453?p=preview
我正在使用 Angular v1.3.16

最佳答案

link之后,您不能将allowInvalidtype="number"属性一起使用。

Issues with HTML5 constraint validation

In browsers that follow the HTML5 specification, input[number] does not work as expected with ngModelOptions.allowInvalid. If a non-number is entered in the input, the browser will report the value as an empty string, which means the view / model values in ngModel and subsequently the scope value will also be an empty string.

关于javascript - Angular ngModelOptions allowInvalid无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30683673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com