Components: Md-Select cannot set default options when using a Multiple Select

Created on 7 Jun 2017  路  3Comments  路  Source: angular/components

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

Ideally when the array that you pass into ngModel on md-select is used in order to select all of the md-option's that match.

What is the current behavior?

Currently no options are selected from the array at all.

What are the steps to reproduce?

Set multiple on your md-select and then pass in a subset of the full list of options to the ngModel on the md-select.

Here is a plunk showing how this behavior doesn't currently work:
http://plnkr.co/edit/aUh0OJUtevRUekcVcovV

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

My use-case would be that I normally use multiple with md-select but would like to continue to have default values in that form, for cases when a user might be editing pre-existing values.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

N/A

Is there anything else we should know?

It's possible that maybe I'm just doing this wrong? But otherwise I couldn't find documentation to support this use case.

Most helpful comment

I looked into it @KyleMcNutt. Everything works as expected. Your Plunkr doesn't work, because the items are compared by reference, not by value. Since the value inside the selectedItems isn't a part of the items, it won't be selected. Here's a working version of your Plunkr. There are a couple of ways to work around it:

  1. Ensure that the items and the preselected value are referencing the same object.
  2. Select the items by id and map them to the their full value before you send them to the server.

All 3 comments

I looked into it @KyleMcNutt. Everything works as expected. Your Plunkr doesn't work, because the items are compared by reference, not by value. Since the value inside the selectedItems isn't a part of the items, it won't be selected. Here's a working version of your Plunkr. There are a couple of ways to work around it:

  1. Ensure that the items and the preselected value are referencing the same object.
  2. Select the items by id and map them to the their full value before you send them to the server.

@crisbeto Sure enough, thanks for the help! This behavior should probably be documented somewhere as to avoid this confusion in the future?

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

MurhafSousli picture MurhafSousli  路  3Comments

constantinlucian picture constantinlucian  路  3Comments

vitaly-t picture vitaly-t  路  3Comments

savaryt picture savaryt  路  3Comments

RoxKilly picture RoxKilly  路  3Comments