【发布时间】:2015-09-09 16:48:30
【问题描述】:
我的结构如下所示:http://jsfiddle.net/deeptechtons/TKVH6/
<div>
<ul ng-controller="checkboxController">
<li>Check All
<input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" />
</li>
<li ng-repeat="item in Items">
<label>{{item.Name}}
<input type="checkbox" ng-model="item.Selected" />
</label>
</li>
</ul>
</div>
angular.module("CheckAllModule", [])
.controller("checkboxController", function checkboxController($scope) {
$scope.Items = [{
Name: "Item one"
}, {
Name: "Item two"
}, {
Name: "Item three"
}];
$scope.checkAll = function () {
if ($scope.selectedAll) {
$scope.selectedAll = true;
} else {
$scope.selectedAll = false;
}
angular.forEach($scope.Items, function (item) {
item.Selected = $scope.selectedAll;
});
};
});
选中或取消选中全部选中时,会选中所有其他复选框。但是选择“检查所有”时,我取消选择其中一个项目,我希望“检查所有”以取消选择。
提前致谢!
(PS:感谢 JSFiddle 的 deeptechtons)
【问题讨论】:
-
谁否决了这个问题,你能告诉我原因吗?将来会有所帮助。谢谢!
标签: angularjs checkbox angularjs-ng-repeat