Angular-material - Change separator in md-select multiple option

僤鯓⒐⒋嵵緔 提交于 2021-01-27 14:41:52

问题


I have an md-select in my form with multiple options (same as demo in Angular Material site). It shows a comma separated list of selected options in its input field. Is there any way to change separator? (for example change comma to star or another UTF-8 character).


回答1:


You can do something with pure CSS. You should hide the commas using visibility: collapse and after that, you can add a Unicode icon with :after or :before pseudo-element.

PLUNKER

HTML

<md-select class="my-select" ng-model="vm.selectedItem" multiple>
  <md-option ng-value="item.id" ng-repeat="item in vm.items">{{ item.name }}</md-option>
</md-select>

CSS

.my-select[multiple] .md-select-value span:first-child {
  visibility: collapse;
}

.my-select[multiple] .md-select-value .md-text {
  display: inline-block !important;
  visibility: visible;
}

.my-select[multiple] .md-select-value .md-text:not(:last-child):after {
  content: '\2605'; /* star */
  margin: 0 -5px 0 5px;
}

There you go a list of Glyphs that you can use.
Also, you can add a font-awesome icon with css if you want.



来源:https://stackoverflow.com/questions/46724777/angular-material-change-separator-in-md-select-multiple-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!