components icon indicating copy to clipboard operation
components copied to clipboard

md-select: add compareWith function

Open kara opened this issue 9 years ago • 10 comments

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 avatar Jan 24 '17 19:01 kara

@kara is this still being considered?

jt-helsinki avatar Apr 21 '17 11:04 jt-helsinki

What news?

mackva avatar May 14 '17 14:05 mackva

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

linuradu avatar May 19 '17 07:05 linuradu

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

pdavin-zz avatar Jun 14 '17 22:06 pdavin-zz

It looks like there is a PR, but it now has a merge conflict: https://github.com/angular/material2/pull/4540

kweinmeister avatar Jun 21 '17 15:06 kweinmeister

Has anyone implemented a workaround for this issue?

jeanpchr avatar Jul 19 '17 18:07 jeanpchr

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 avatar Jul 26 '17 17:07 ppham27

Desperately need this 👍

reppners avatar Aug 14 '17 14:08 reppners

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>

picheli20 avatar May 16 '18 20:05 picheli20

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.