SKL
SKL

Reputation: 1453

Angular material datatable checkbox keep value in array when Select all or select single item and remove if unselect

When user select master checkbox all values must be push to array. Value must splice from array when user unselect specific checkbox and push again to array if select again. Here is my sample code in stackblitz. Thank you in advance.

Upvotes: 0

Views: 1013

Answers (1)

Fabian Küng
Fabian Küng

Reputation: 6193

There were a few mistakes in your code, notably that you didn't check for the correct property on the MatCheckboxChange event. You checked for the check property, when it is actually called checked, see here.

Also you tried to use splice with a string (the name property of the current row) and number argument, when in fact it takes number, number.

A proper IDE would notify you of these mistakes and help you solve them.

Here is a working version of your table.

Upvotes: 2

Related Questions