snowflakes74 snowflakes74 - 1 year ago 53
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;

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download