I have tried all day to get mat-selection-list to retain the selected objects when refreshing data ie. Pagination but without success.
If I select object A ( {name, id} ) in page 1, and switch to page 2 and back to page 1 I would expect object A to still be marked as checked but this doesn't happen and I'm losing my mind.
I have tried several things:
- 2 way binding with
[(ngModel)]="selectedOptions" [compareWith]="compareFunction". But as soon as I switch to page 2, due to the 2 way binding, mat-selection-list automatically clearsselectedOptionsbecause it can't find the objects in the list as I have switched to page 2.
- Use reactive forms with
[formControl]="itemsControl" (selectionChange)="onSelectionChanged($event)"andform.setValue``. This way themat-selection-listdoesn' clear it but when returning to page 1 objects are no rechecked automatically. If I select one thenonSelectionChange` reports the current one as the only object selected.
I have ran out of ideas, googled for hours, I'm starting to think it's a bug?
Any help is greatly appreciated.
[selected]="item.selected"it gets unchecked even if{{ item.selected }}is clearly still true. - Simon_Weaver