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

feature(select): trackByFn #6970

Closed
julianobrasil opened this issue Sep 10, 2017 · 3 comments
Closed

feature(select): trackByFn #6970

julianobrasil opened this issue Sep 10, 2017 · 3 comments

Comments

@julianobrasil
Copy link
Contributor

julianobrasil commented Sep 10, 2017

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

If you change the datasource used to generate the options, the selected value should be kept. It already works like this for primitive options' values. For complex options' values, something like *ngFor's trackByFunction could take care of which attribute would define whether one of the new options is equals to the one already selected.

What is the current behavior?

When the options' values are not primitive types and you change the options' datasource, the selected value is unset even if it's present in the new datasource.

What are the steps to reproduce?

Plunk: https://plnkr.co/edit/GJn833kKV1qaMthxDmMe?p=preview

In the plunk, select an option and then click on the reload datasource button. The selected value will not be kept.

What is the use-case or motivation for changing an existing behavior?

It would simplify the developer's code if something like trackBy="'id'" or trackBy="'owner.personalDocuments.socialSecurityNumber'" was possible to do.

@rafaelss95
Copy link
Contributor

rafaelss95 commented Sep 10, 2017

That's what compareWith is for:

<md-select [compareWith]="compareFn">
  ...
</md-select>

compareFn: ((f1: any, f2: any) => boolean) | null = this.compareByValue;

compareByValue(f1: any, f2: any) { 
  return f1 && f2 && f1.value === f2.value; 
}

Check this working here

@julianobrasil
Copy link
Contributor Author

Oh, in this case... closing this issue. Thanks.

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants