Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatSelectionList: selectedOptions.selected not up to date in onChange #8584

Closed
probert94 opened this issue Nov 22, 2017 · 1 comment · Fixed by #8599
Closed

MatSelectionList: selectedOptions.selected not up to date in onChange #8584

probert94 opened this issue Nov 22, 2017 · 1 comment · Fixed by #8599
Assignees
Labels
P4 A relatively minor issue that is not relevant to core functions

Comments

@probert94
Copy link

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?

  1. Create a Angular-Material application with a MatSelectionList. You might need another component (for example an input) too, to reproduce the bug.
  2. Add an onChange-Listener to the MatSelectionList and console.log the value of selectedOptions.selected.
  3. Focus the input (or any other material component in your app).
  4. Select one of the MatListOptions inside the MatSelectionList and 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.

@crisbeto crisbeto self-assigned this Nov 22, 2017
@crisbeto crisbeto added has pr P4 A relatively minor issue that is not relevant to core functions labels Nov 22, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 22, 2017
…ge subscription

Fixes the `selected` value being out of date in the `SelectionModel`, if it is accessed inside an `onChange` subscription.

Fixes angular#8584.
tinayuangao pushed a commit that referenced this issue Dec 1, 2017
…ge subscription (#8599)

Fixes the `selected` value being out of date in the `SelectionModel`, if it is accessed inside an `onChange` subscription.

Fixes #8584.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
2 participants