当angularjs检查获取复选框的值 [英] get value of checkbox when checked with angularjs

查看:167
本文介绍了当angularjs检查获取复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查时,如何获得复选框的价值?我的问题是我alrdy了NG-模式其他的东西在我的<输入>

how to get value of checkbox when checked? My problem is I alrdy had a ng-model for other stuff in my <input>

http://plnkr.co/edit/wyTRa8FVkGaEPX6BgYXb?p=$p$ PVIEW

我要收集数据,这样,当用户点击提交,我可以得到选中的复选框的值。

I want to collect the data so that when user clicked submit, I can get the value of checked checkbox.

推荐答案

您需要使用 NG-模型 NG-真值来追踪你选择了什么。
声明数组来跟踪值

You need to use ng-model and ng-true-value to track what you have selected. Declare an array to track values

$ scope.selectedValues​​ = [];

然后使用以下绑定

<input ng-show="showC || checked" type="checkbox" id="{{$index}}" ng-model='selectedValues[$index]' ng-true-value='{{item.name}}'>

请参阅我的更新plunkr http://plnkr.co/edit/KWh5CzZa3OcqKjjhocDz?p = preVIEW

See my updated plunkr http://plnkr.co/edit/KWh5CzZa3OcqKjjhocDz?p=preview

这篇关于当angularjs检查获取复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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