Angularjs Angularfire通过复选框删除项目
我正在使用Angularfire,我想通过复选框删除项目 还有一个按钮可以执行“全部检查”,另一个按钮可以执行“取消检查” HTML 我不知道如何通过复选框删除项目,或者如何使“checkAll”按钮工作Angularjs Angularfire通过复选框删除项目,angularjs,checkbox,firebase,angularfire,removeall,Angularjs,Checkbox,Firebase,Angularfire,Removeall,我正在使用Angularfire,我想通过复选框删除项目 还有一个按钮可以执行“全部检查”,另一个按钮可以执行“取消检查” HTML 我不知道如何通过复选框删除项目,或者如何使“checkAll”按钮工作 如果有人能告诉我您的答案,我将不胜感激。以下是您需要勾选/取消勾选并删除项目的功能: $scope.checkAll = function() { $scope.newslist.forEach(function(el) { el.checked = true;
如果有人能告诉我您的答案,我将不胜感激。以下是您需要勾选/取消勾选并删除项目的功能:
$scope.checkAll = function() {
$scope.newslist.forEach(function(el) {
el.checked = true;
$scope.newslist.$save(el);
});
};
$scope.uncheckAll = function() {
$scope.newslist.forEach(function(el) {
el.checked = false;
$scope.newslist.$save(el);
});
}
$scope.remove = function() {
$scope.newslist.forEach(function(item) {
if (item.checked) {
$scope.newslist.$remove(item);
}
});
};
演示:
我为ngModel指令添加了选中的属性
HTML变成:
<li ng-repeat="item in newslist">
<input type="checkbox" ng-model="item.checked">{{item.newsTitle}}
</li>
<button ng-click="checkAll()">check all</button>
<button ng-click="uncheckAll()">uncheck all</button>
<button ng-click="remove()">Remove</button>
{{item.newsttitle}
全部检查
全部取消选中
去除
哇,非常感谢。我从没想过检查了属性。这使事情变得简单。嗨,我想知道如果我想将按钮checkAll()
和按钮uncheckAll()
组合成一个复选框,我该怎么办?非常感谢。实际上,我尝试了一种愚蠢的方法,我写了两个复选框,并使用ngShow
使其中一个可见或不可见。我不擅长使用$watch
。你真是太好了!非常感谢你!没问题,ngShow方式也很智能,只是如果至少有一个未选中,您需要确保checkAll复选框被隐藏。如果答案有帮助,请随意接受。
$scope.checkAll = function() {
$scope.newslist.forEach(function(el) {
el.checked = true;
$scope.newslist.$save(el);
});
};
$scope.uncheckAll = function() {
$scope.newslist.forEach(function(el) {
el.checked = false;
$scope.newslist.$save(el);
});
}
$scope.remove = function() {
$scope.newslist.forEach(function(item) {
if (item.checked) {
$scope.newslist.$remove(item);
}
});
};
<li ng-repeat="item in newslist">
<input type="checkbox" ng-model="item.checked">{{item.newsTitle}}
</li>
<button ng-click="checkAll()">check all</button>
<button ng-click="uncheckAll()">uncheck all</button>
<button ng-click="remove()">Remove</button>