material icon indicating copy to clipboard operation
material copied to clipboard

md-select option to specify display text template after selection.

Open Kasahs opened this issue 10 years ago • 2 comments

I have a simple use case where I wish to show a bunch of country names with their dialing codes to my users. On selecting a country i want the selected option to only show the dialing code. I don't see any way to specify a custom template for the select box based on the selected option.

ex. if user selects option India (+91) then the select box display text should change to +91 while the model binding with the country object is maintained.

Here is my code snippet:

<md-select ng-model="ctrl.selectedCountry" ng-model-options="{trackBy: '$value.code && $value.name && $value.prefix'}">
    <md-option ng-repeat="country in ctrl.countries" ng-value= "{{ country }}" >
        {{ country.name }} ({{ country.prefix }})
    </md-option>
</md-select>

Is there any way to achieve this?

Kasahs avatar Dec 11 '15 11:12 Kasahs

Was curious of the progress on this feature...working on a piece that could benefit from this.

afreeland avatar Apr 14 '16 17:04 afreeland

Well, I also need this feature, and I implemented this in an awkward way now...

Something like: <md-select ng-model="ctrl.selectedCountry"> <md-option ng-repeat="country in ctrl.countries" ng-value= "{{ country }}" > {{ country.name }}<span class="prefix"> ({{ country.prefix }})</span> </md-option> </md-select>

And CSS: md-option .prefix { display: none; }

ycy233 avatar Nov 07 '17 07:11 ycy233