选择所有带有 angular JS 的复选框 [英] select all checkboxes with angular JS
本文介绍了选择所有带有 angular JS 的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用一个复选框选中所有复选框.但是怎么做呢?
I am trying to select all checkboxes with one single checkbox. But how to do that?
这是我的 HTML:
<input type="checkbox" ng-model="selectAll" ng-click="checkAll()" />
<!-- userlist -->
<!--<div id="scrollArea" ng-controller="ScrollController">-->
<table class="table">
<tr>
<th>User ID</th>
<th>User Name</th>
<th>Select</th>
</tr>
<tr ng-repeat="user in users | filter:search">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td><input type="checkbox" ng-click="usersetting(user)" ng-model="user.select"></td>
<td><tt>{{user.select}}</tt><br/></td>
</tr>
</table>
我创建了一个额外的复选框来选择和取消选择所有复选框.
I create an extra checkbox to selecet and unselect all checkboxes.
JS:
.controller('UsersCtrl', function($scope, $http){
$http.get('users.json').then(function(usersResponse) {
$scope.users = usersResponse.data;
});
$scope.checkAll = function () {
angular.forEach($scope.users, function (user) {
user.select = true;
});
};
});
我也试过这个,但它们都不适合我:(
I tried this too, but none of them works for me :(
$scope.checkAll = function () {
angular.forEach($scope.users, function (user) {
user.select = $scope.selectAll;
});
};
推荐答案
ng-controller
和 ng-app
和 angular 的容器 div.module
.
user.select = $scope.selectAll
是正确的变体.
https://jsfiddle.net/0vb4gapj/1/
这篇关于选择所有带有 angular JS 的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文