Selections in modal persisting even after cancel or close

I open a modal with a list of checkboxes (all checked), uncheck some of them, then when I cancel the modal and reopen it again the checkboxes are unchecked even though I cancelled.

StackBlitz here.

I’m trying to use a list of checkboxes instead of a select component because I want a ‘Select all’ button.

I found this similar issue but it is unanswered.

I want to know why the selection is persisting? How do I get it to forget the selection when the modal is dismissed? (Unless the user selects Save, but I haven’t implemented that yet).

Fairly new to all this, so any help appreciated!

1 Like

You cloud do

1 Like

Thanks for the reply! That works for this example, but I’m trying to get to a point where if the user saves then their selection will be remembered, so setting all checkboxes to true would overwrite that.

Found the problem, I didn’t copy an array properly, so changes were being applied to my original, reference array. Came across a solution here https://dev.to/rsschouwenaar/how-to-make-a-real-copy-of-a-javascript-array-with-objects-without-a-reference-5md