gpt4 book ai didi

angularjs - 当值为零时, Angular 数据绑定(bind)返回 NaN

转载 作者:行者123 更新时间:2023-12-02 06:33:37 25 4
gpt4 key购买 nike

我正在做一些像这样的简单数据绑定(bind):

<input type="text" class="form-control" model="amount">
<label>Your amount is {{amount * 10 }}</label>

但是,最初,当文本输入为空时,它返回 NaN。

如何防止 Angular 发生这种情况?

最佳答案

你可以试试这个:

<input type="text" class="form-control" model="amount">
<label>Your amount is {{ (+amount) * 10 }}</label>

根据定义,HTML 文本输入是文本。添加的 + 会在使用前将其转换为数字。

关于angularjs - 当值为零时, Angular 数据绑定(bind)返回 NaN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26083122/

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