gpt4 book ai didi

javascript - ng-model 和 ng-max 相同的值

转载 作者:行者123 更新时间:2023-11-29 23:19:43 25 4
gpt4 key购买 nike

我有ng-repeat带有输入字段(数字)的表格,以及从 API 获取的动态数据。

问题是 ng-modelng-max

这是代码

<input type="number" ng-model="item.impressions" ng-max="item.impressions" class="form-control inputPolje" name="item.impressions"/>

View 中的输出: Number: 5000

ng-max与 ng-model 的值相同,也是 5000。

当有人试图在 ng-max 中输入大于此的数字时我显示一条错误消息。

因为,我的ng-modelng-max具有相同的值,在本例中为 5000,当我在输入字段中输入任何其他数字时,例如 111111111,ng-model有新的值(value)但ng-max也得到相同的值 111111111 并且不抛出错误。

如何解决?谢谢

最佳答案

假设您的 ng-max 需要 item.impressions 的初始值,您可以尝试以下操作

<div ng-init = "item.maxValue = item.impressions">
<input type="number" ng-model="item.impressions" ng-max="item.maxValue" class="form-control inputPolje" name="item.impressions"/>
</div>

Demo

关于javascript - ng-model 和 ng-max 相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51167971/

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