Skip to content

md-select: add compareWith function #2785

Closed

Description

@kara

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.

Activity

  1. added
    feature
    on Jan 24, 2017
  2. self-assigned this
    on Jan 24, 2017
  3. jt-helsinki commented on Apr 21, 2017

    @jt-helsinki

    @kara is this still being considered?

  4. mackva commented on May 14, 2017

    @mackva

    What news?

  5. linuradu commented on May 19, 2017

    @linuradu

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

  6. pdavin-zz commented on Jun 14, 2017

    @pdavin-zz

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

  7. kweinmeister commented on Jun 21, 2017

    @kweinmeister

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

  8. jeanpchr commented on Jul 19, 2017

    @jeanpchr

    Has anyone implemented a workaround for this issue?

  9. ppham27 commented on Jul 26, 2017

    @ppham27
    Contributor

    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.

  10. reppners commented on Aug 14, 2017

    @reppners

    Desperately need this 👍

  11. picheli20 commented on May 16, 2018

    @picheli20

    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>
  12. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  13. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions