diff --git a/src/components-examples/material/table/table-selection/table-selection-example.ts b/src/components-examples/material/table/table-selection/table-selection-example.ts index 8aa13f5aaee1..6916c1d920aa 100644 --- a/src/components-examples/material/table/table-selection/table-selection-example.ts +++ b/src/components-examples/material/table/table-selection/table-selection-example.ts @@ -44,9 +44,12 @@ export class TableSelectionExample { /** Selects all rows if they are not all selected; otherwise clear selection. */ masterToggle() { - this.isAllSelected() ? - this.selection.clear() : - this.dataSource.data.forEach(row => this.selection.select(row)); + if (this.isAllSelected()) { + this.selection.clear(); + return; + } + + this.selection.select(...this.dataSource.data); } /** The label for the checkbox on the passed row */