Angular mat-table function isAllSelected() running infinitely

60 Views Asked by At

I am using an Angular material mat-table for showing table data, but I noticed that this function is executing infinitely after we initialize datasource of the table.

html code:

         <ng-container matColumnDef="select">
                        <th mat-header-cell *matHeaderCellDef style="padding: 0px;">
                            <mat-checkbox (change)="$event ? toggleAllRows() : null"
                                [checked]="selection.hasValue() && isAllSelected()" [indeterminate]="false"
                                [aria-label]="checkboxLabel()">
                            </mat-checkbox>
                        </th>
                        <td mat-cell *matCellDef="let row">
                            <mat-checkbox (click)="$event.stopPropagation()"
                                (change)="$event ? selection.toggle(row) : null" (change)="$event ? selectRow($event, row) : null"
                                [checked]="selection.isSelected(row)" [aria-label]="checkboxLabel(row)">
                            </mat-checkbox>
                        </td>
                    </ng-container>

.ts code:

  isAllSelected() {


const numSelected = this.selection.selected.length;

this.rowsToSend = this.selection.selected;

console.log('is all selected execution started');

return numSelected === numRows; 

 }

Once data is loaded it starts infinitely.

I want to know if it is the default behavior of this, if yes it leads to memory leakage. If not, how to deal with this?

0

There are 0 best solutions below