material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete / md-select support for ng-options

Open hodeyp opened this issue 11 years ago • 13 comments

It looks as if both the md-autocomplete and md-select directives do not have the ability to work with key/name pairs in the way that ng-options allows?

I want to be able to set the key in ng-value, and value in the display label. is this currently possible?

hodeyp avatar Feb 19 '15 06:02 hodeyp

+1!

This Plunker shows the differences between a native select (with support for ng-options select as label for value in array syntax) and md-select. Where the native select-element can have a label on both the select and its options, md-select currently only supports labels on the options.

Demo using v0.8.0-rc1-master-eda14e9. Change comments in source to change to master.

Note that in ng-options you can even apply a filter to the label in select as label for value in array, e.g. select as label | translate for value in array using the excellent angular-translate.

Frank3K avatar Feb 19 '15 19:02 Frank3K

+1

This is EXACTLY what I needed except for this issue...

If your items for the options are objects, you may want one field for the option drop-down and another for value (the object likely). However upon selection, md-select is using the ng-model (which is an object in this case). There should be a label (preferred) you can set on md-select or use the "display" value from the selected md-option instead of the ng-model. Note this is not the same as placeholder

The plunker from Frank3K I think shows the issue. In case it is not clear (took me a second to see that it was the same issue) I created a more verbose example here: http://plnkr.co/edit/ZVfNcK?p=preview

A syntax with label="name" might be a clean option

<md-select ng-model="selectedFilter" label="name" placeholder="Select a filter"> <md-option ng-value="opt" ng-repeat="opt in filters">{{ opt.name }}</md-option> </md-select>

jadrake75 avatar Feb 20 '15 19:02 jadrake75

@Frank3K's and @jadrake75's comments are about a different issue than the originally reported one. If I understand correctly, @hodeyp is asking for support for (key, value) in someObject (for mdAutocomplete/mdSelect), whereas @Frank3K and @jadrake75 are asking for a way to configure the display of the selected value (instead of displaying the selected object itself), which applies to mdSelect only (I believe).

I think these should be separate issues.

gkalpak avatar Feb 20 '15 19:02 gkalpak

+1

alirezamirian avatar Feb 24 '15 08:02 alirezamirian

+1

Also ran into this issue, basically I am coming from plain angular <select> and now would like to use <md-select>.

In my current angular approach I store a selected item's "t.id" in scope var "mydata.types_id", but I would like the user to see not the id but the textual name "t.name" of the type: <select name="types_id" data-ng-model="mydata.types_id" data-ng-options="t.id as t.name for t in types" required> </select>

mfdlr avatar Feb 25 '15 18:02 mfdlr

Closing as duplicate of #1837. We agree it'd be great to have but you can achieve the same with ng-repeat for now. Regarding the display value, md-select now uses whatever you supply as the text value to the node.

rschmukler avatar Apr 01 '15 21:04 rschmukler

I just read the thread and it seems to me that the conversation was stolen by md-select.

What about md-autocomplete? I have a use case where the user should see some text value (for example a country name) and the model should contain a country code. With md-select it is easy. How can I achieve that with md-autocomplete?

mikedobrin avatar Jul 29 '15 09:07 mikedobrin

+1 for md-autocomplete

alexcriss avatar Aug 20 '15 07:08 alexcriss

+1

thomasbertet avatar Aug 24 '15 14:08 thomasbertet

+1

leex avatar Aug 31 '15 03:08 leex

+1

Greg-Shaw avatar Aug 31 '15 03:08 Greg-Shaw

+1

cuongpro2511 avatar Nov 06 '15 08:11 cuongpro2511

I am having major performance issues with ng-repeat inside md-select for very large drop downs. It takes a considerable amount of time to render the dom on first load (about 5 secs). Would having ng-options support in md-select improve performance? The parties object below is about a thousand objects.

<md-select multiple ng-model="myPartyIds" ng-model-options="{trackBy: '$value.partyId'}"> <md-option ng-value="party" ng-repeat="party in ::parties | orderBy:'party.shortDisplayName'">{{ party.shortDisplayName }}</md-option> </md-select>

jonpopp avatar Feb 12 '16 17:02 jonpopp