Skip to content

fix(selection-model): inaccurate selected value when accessed in change subscription #8599

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

Merged
merged 1 commit into from
Dec 1, 2017

Conversation

crisbeto
Copy link
Member

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

Fixes #8584.

…ge subscription

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

Fixes angular#8584.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 22, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 27, 2017
@tinayuangao tinayuangao merged commit 0f7fbda into angular:master Dec 1, 2017
@simeyla
Copy link

simeyla commented Jan 7, 2018

Any chance of ever add selected to the interface?

 export declare class SelectionChange<T> {
     added: T[] | undefined;
     removed: T[] | undefined;
     selected: T[] | undefined;
     constructor(added?: T[] | undefined, removed?: T[] | undefined);
 }

I realize it's a change event, but as a convenience it would be very handy.

Edit: I see now why that would be inefficient. The _selected array isn't up to date when the change event is emitted so you wouldn't want to run through the whole array just to raise the change event.

@crisbeto
Copy link
Member Author

crisbeto commented Jan 8, 2018

@simeyla the intention with the selected is that we try to avoid recomputing it until it is requested. That being said, I think that we can expose the SelectionModel, that triggered the event, for convenience which will allow you to get the selected value without having to reach outside the function.

crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 8, 2018
Exposes the selection model that dispatched an event inside the event itself. This is mostly for convenience, because it allows the consumer to access the selected value and other properties without having to reach outside the callback.

Relates to the discussion in angular#8599.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 8, 2018
Exposes the selection model that dispatched an event inside the event itself. This is mostly for convenience, because it allows the consumer to access the selected value and other properties without having to reach outside the callback.

Relates to the discussion in angular#8599.
jelbourn pushed a commit that referenced this pull request Jan 21, 2018
Exposes the selection model that dispatched an event inside the event itself. This is mostly for convenience, because it allows the consumer to access the selected value and other properties without having to reach outside the callback.

Relates to the discussion in #8599.
jelbourn pushed a commit that referenced this pull request Jan 23, 2018
Exposes the selection model that dispatched an event inside the event itself. This is mostly for convenience, because it allows the consumer to access the selected value and other properties without having to reach outside the callback.

Relates to the discussion in #8599.
@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 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatSelectionList: selectedOptions.selected not up to date in onChange
5 participants