复选框输入在未选中时未定义-AngularJS [英] Checkbox input undefined when unchecked - AngularJS

查看:56
本文介绍了复选框输入在未选中时未定义-AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AngularJS复选框有问题,当未选中它们时,它们变为undefined.无法弄清楚为什么会这样.

I have an issue with my AngularJS checkbox where they become undefined when they are unchecked. Can't figure out why this is happening.

<input type="checkbox" name="available" ng-model="formData.available" ng-true-value="1" ng-false-value="0" required>

使用上面的代码;页面加载的默认值为0.当其选中时,它变为1.当我取消选中它时,它变成undefined

With the above code; default on page load is 0. when Its checked it becomes 1. When I uncheck it it becomes undefined

任何帮助表示赞赏.

推荐答案

感谢评论,我意识到required选项不是必需的,并且是问题的原因.谢谢大家!

Thanks to the comments I've realised that the required option is not necessary and was the cause of the issue. Thanks guys!

这篇关于复选框输入在未选中时未定义-AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆