Components: md-select: add compareWith function

Created on 24 Jan 2017  路  10Comments  路  Source: angular/components

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.

feature

Most helpful comment

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

All 10 comments

@kara is this still being considered?

What news?

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

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

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

Has anyone implemented a workaround for this issue?

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.

Desperately need this 馃憤

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>

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abdulkareemnalband picture abdulkareemnalband  路  165Comments

kara picture kara  路  94Comments

jeffbcross picture jeffbcross  路  126Comments

Daugoh picture Daugoh  路  79Comments

mmalerba picture mmalerba  路  127Comments