-
Couldn't load subscription status.
- Fork 6.8k
Description
Bug, feature request, or proposal:
When I listen to change events of the MatSelectionList and I use selectedOptions.selected to know the current selected values, they are not always up to date.
Problem lies in Selection.ts#125:
The onChange.next is called, before the cached value of _selected is reseted.
Therefore the get selected() will return the old value.
The bug only seems to occure, if you first set a value of another material-component, so it might be a timing-problem.
What is the expected behavior?
The cached value of _selected should be reset, so that I get the current value in onChange.
What is the current behavior?
When calling selectedOptions.selected, I sometimes get the previous value.
What are the steps to reproduce?
- Create a Angular-Material application with a MatSelectionList. You might need another component (for example an input) too, to reproduce the bug.
- Add an
onChange-Listener to theMatSelectionListandconsole.logthe value ofselectedOptions.selected. - Focus the input (or any other material component in your app).
- Select one of the
MatListOptionsinside theMatSelectionListand look at the value in the console.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
I am using @angular/material and @angular/cdk version 5.0.0-rc0 as well as @angular version 5.0.1
Is there anything else we should know?
A simple window.setTimeout(() => console.log(selectedOptions.selected)) seems to solve the problem.