如何检查是否有任何复选框被选中角 [英] How to check if any Checkbox is checked in Angular
本文介绍了如何检查是否有任何复选框被选中角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何功能或NG-的的东西的检查,如果任何显示复选框被选中?
Is there any function or ng-something to check if any of the displayed Checkboxes are checked?
我要通过在 NG-点击=值功能()并通过值传递。我可以步行去看看我的数组,如果任何价值在里面。
I have the values through the ng-click="function()" and pass the values through. I can go by foot and check my array if any value is inside.
我要激活/停用下一步 - 按钮(如果有)复选框
检查。
I want to activate/deactivate the "next"-button if any Checkbox is checked.
什么是最简单的方法?
推荐答案
您可以这样做:
function ChckbxsCtrl( $scope , $filter ){
$scope.chkbxs = [{label:"Led Zeppelin", val:false },
{label:"Electric Light Orchestra", val:false },
{label:"Mark Almond", val:false }];
$scope.$watch( "chkbxs" , function(n,o){
var trues = $filter("filter")( n , {val:true} );
$scope.flag = trues.length;
}, true );
}
和一个模板:
<div ng-controller="ChckbxsCtrl">
<div ng-repeat="chk in chkbxs">
<input type="checkbox" ng-model="chk.val" />
<label>{{chk.label}}</label>
</div>
<div ng-show="flag">I'm ON when band choosed</div>
</div>
工作: http://jsfiddle.net/cherniv/JBwmA/
更新:或你可以去有点不同的方式,而无需使用 $范围
的 $腕表()
的方法,如:
UPDATE: Or you can go little bit different way , without using $scope
's $watch()
method, like:
$scope.bandChoosed = function() {
var trues = $filter("filter")( $scope.chkbxs , {val:true} );
return trues.length;
}
和在模板中做的:
<div ng-show="bandChoosed()">I'm ON when band choosed</div>
小提琴: http://jsfiddle.net/uzs4sgnp/
这篇关于如何检查是否有任何复选框被选中角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文