components icon indicating copy to clipboard operation
components copied to clipboard

md-select default value is not support object?

Open wizardnet972 opened this issue 9 years ago • 5 comments

Bug, feature request, or proposal:

I want to display selected value in md-select, the value is an Object. not string.

What is the expected behavior?

to display the correct option from the select.

What is the current behavior?

not display. in the plunker should be: "United States" at the begging.

What are the steps to reproduce?

here: https://plnkr.co/edit/nCJLd5?p=preview

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

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

Is there anything else we should know?

wizardnet972 avatar Aug 30 '17 10:08 wizardnet972

This is not a bug. Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.

donroyco avatar Aug 30 '17 10:08 donroyco

As pointed out by @donroyco, this is not a bug. Even though the Object you passed to selectedCountry looks like countries[1], they are different objects so the select wouldn't know which option to display.

In order to select any of the options, you have to select one of the objects you passed to the select, i.e. an Object from the countries list. Here's an updated plunker: https://plnkr.co/edit/GmlISyGT3BSBWxAryEiD?p=preview

alex321 avatar Aug 30 '17 11:08 alex321

You can now pass a compareWith function to MdSelect. See https://material.angular.io/components/select/api

willshowell avatar Aug 30 '17 12:08 willshowell

@willshowell YEAH!!! U R D BEST! :)

wizardnet972 avatar Aug 30 '17 13:08 wizardnet972

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.