snowflakes74 snowflakes74 - 3 months ago 7x
AngularJS Question

How to set all the rows of ng-repeat to be selected in Angular

I have a smimple ng-repeat that displays user details. I am trying to set all the rows to be selected.

Currently I can manually click and select all the rows individually using following code:

<tr ng-repeat="room in classrooms" ng-class="{'selected': room.selected}" ng-click="select(room)">

in controller

$ = function(item) {
item.selected ? item.selected = false : item.selected = true;

and to get data from the selected rows I use following logic

$scope.getAllSelectedRows = function()
var x = $filter("filter")($scope.classrooms,
selected: true
}, true);



$scope.toggleSelectAll = function()
angular.forEach($scope.classrooms, function(room) {
room.selected ? room.selected = false : room.selected = true;


Set up a new function in your controller:

$scope.selectAll = function() {
    angular.forEach(classrooms, function(room) {
        room.selected = true

And then you can create a button in your html to call this function.