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

md-select: add compareWith function #2785

Closed
kara opened this issue Jan 24, 2017 · 10 comments
Closed

md-select: add compareWith function #2785

kara opened this issue Jan 24, 2017 · 10 comments
Assignees
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix

Comments

@kara
Copy link
Contributor

kara commented Jan 24, 2017

Currently, md-select values are compared by object reference. This is a bit inflexible. We want to allow people to compare options by a custom comparator in case they only care about the object's ID or some other property.

Example markup:

<md-select placeholder="Food" [(ngModel)]="food" [compareWith]="compareById">
   <md-option *ngFor="let food of foods" [value]="food"> {{ food.name }} </md-option>
</md-select>
compareById(obj1, obj2) {
   return obj1.id === obj2.id;
}

This will be parallel to functionality being added to native selects in core.

@kara kara added the feature This issue represents a new feature or feature request rather than a bug or bug fix label Jan 24, 2017
@kara kara self-assigned this Jan 24, 2017
@jt-helsinki
Copy link

@kara is this still being considered?

ppham27 added a commit to ppham27/material2 that referenced this issue May 14, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@mackva
Copy link

mackva commented May 14, 2017

What news?

ppham27 added a commit to ppham27/material2 that referenced this issue May 15, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@linuradu
Copy link

Sounds good, regarding commit :) When will be the next release?

ppham27 added a commit to ppham27/material2 that referenced this issue Jun 7, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Jun 10, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@pdavin-zz
Copy link

Any update on this? Looks like there's a fix in a forked branch but not submitted for PR / review yet.

@kweinmeister
Copy link

It looks like there is a PR, but it now has a merge conflict: #4540

ppham27 added a commit to ppham27/material2 that referenced this issue Jun 22, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Jul 7, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Jul 9, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Jul 11, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Jul 15, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@jeanpchr
Copy link

jeanpchr commented Jul 19, 2017

Has anyone implemented a workaround for this issue?

ppham27 added a commit to ppham27/material2 that referenced this issue Jul 25, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Jul 26, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@ppham27
Copy link
Contributor

ppham27 commented Jul 26, 2017

I have PR #4540 open. I'm pretty good about rebasing it pretty often, so if you really need the feature, you could build against my branch. I'm not sure when/if they plan on merging it into master.

ppham27 added a commit to ppham27/material2 that referenced this issue Jul 29, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@reppners
Copy link

Desperately need this 👍

ppham27 added a commit to ppham27/material2 that referenced this issue Aug 14, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
ppham27 added a commit to ppham27/material2 that referenced this issue Aug 16, 2017
Fixes Issue angular#2250 and Issue angular#2785. Users can supply a custom comparator that tests for equality. The comparator can be changed dynamically at which point the selection may change. If the comparator throws an exception, it will log a warning in developer mode but will be swallowed in production mode.
@kara kara closed this as completed in 054ea4d Aug 21, 2017
@picheli20
Copy link

For me only solved when I've change the ngModel to value. Like:

<md-select placeholder="Food" [(value)]="food" [compareWith]="compareById">
   <md-option *ngFor="let food of foods" [value]="food"> {{ food.name }} </md-option>
</md-select>

@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
feature This issue represents a new feature or feature request rather than a bug or bug fix
Projects
None yet
Development

No branches or pull requests

10 participants