问题
Selection list becomes empty when datasource is updated.
steps: 1. select some users
steps: 2. select second tab
steps: 3. come back to the first tab
selected users are available in chips but not selected in datatable.
look at https://stackblitz.com/edit/angular-v3kjgj?embed=1&file=app/selectusers.component.ts
回答1:
You are saving selection status by the "row" object itself, which are all changed by your loadUsers() call when you change select the first tab. Either don't call loadUsers() every time you click on the first tab (if you need to refresh data, create an "updateUsers()" method that keeps the existing user objects), or change how you save selection status (e.g. by row.id).
来源:https://stackoverflow.com/questions/49045049/selection-list-become-empty-when-datasource-is-updated-datatable-materil2