You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support template content for selected value in md-select #2275
P4A relatively minor issue that is not relevant to core functionsfeatureLabel used to distinguish feature request from other issuesneeds: discussionFurther discussion with the team is needed before proceeding
@kara do you have something in mind regarding this? I would probably like to take a look at it.. also @crisbeto do you expect any problems with this because of multiselect?
I don't expect any issues with multi select since it'll use the same property to get the text. I was actually considering giving this a shot in the next few days.
@crisbeto thanks for your PR. So I guess you intended that with this change you can add the "plain HTML" option as label as follows: <md-select-label [innerHtml]="select.selected?._getHostElement().innerHTML"></md-select-label>
..and you select it, the selected content won't be <img src="whatever.jpg" /> Whatever, it will be stripped down to Whatever. He wants the original unstripped HTML to be there instead. I'm not sure if {{ select.selected?.viewValue }} does that?
Reacted by andreasrueedlinger, Michael Trouw, Joao Grassi and Michal
At least I don't have "thumb_up Nice!" displayed and can work with it until it's fixed (be aware, it does seem to take some time to evaluate the template when opening the select, and the raw html is shown for a short period of time).
P4A relatively minor issue that is not relevant to core functionsfeatureLabel used to distinguish feature request from other issuesneeds: discussionFurther discussion with the team is needed before proceeding
Activity
dougmbarcellos commentedon Dec 22, 2016
Use this to display the formatted html:
<div [innerHtml]="selectedValue"></div>wouterbeukers commentedon Dec 22, 2016
That isn't the issue.
It is about the value what the md-selects shows after you select an option.
This value is stripped of al it's html-tags.
negberts commentedon Dec 27, 2016
The html is stripped here:
get viewValue(): string {
// TODO(kara): Add input property alternative for node envs.
return this._getHostElement().textContent.trim();
}
I would love to change it, but I don't know what the impact will be. There's probably a reason why textContent is taken and not just value
fxck commentedon Feb 28, 2017
@kara do you have something in mind regarding this? I would probably like to take a look at it.. also @crisbeto do you expect any problems with this because of multiselect?
crisbeto commentedon Feb 28, 2017
I don't expect any issues with multi select since it'll use the same property to get the text. I was actually considering giving this a shot in the next few days.
feat(select): add ability to customize the selected value label
andreasrueedlinger commentedon Mar 7, 2017
@crisbeto thanks for your PR. So I guess you intended that with this change you can add the "plain HTML" option as label as follows:
<md-select-label [innerHtml]="select.selected?._getHostElement().innerHTML"></md-select-label>crisbeto commentedon Mar 7, 2017
This is the intended usage @andreasrueedlinger:
andreasrueedlinger commentedon Mar 7, 2017
@crisbeto but that does not fix the problem adressed in this issue, namely that the label does not support Html!
crisbeto commentedon Mar 7, 2017
You can put any HTML you want inside the
md-select-labelelement.fxck commentedon Mar 7, 2017
That's not what he meant I think.
When you have..
..and you select it, the selected content won't be
<img src="whatever.jpg" /> Whatever, it will be stripped down toWhatever. He wants the original unstripped HTML to be there instead. I'm not sure if{{ select.selected?.viewValue }}does that?andreasrueedlinger commentedon Mar 7, 2017
But in your example you use normal binding and
viewValuewhich returns the trimmed textContent, so no Html anymore.My example:
12 remaining items
negberts commentedon Jun 24, 2017
An updated plunker for the problem can be found here: http://plnkr.co/edit/vuF3Pz7UHDXERXZbtiIK?p=preview
mladilav commentedon Jul 6, 2017
Any news about this?
sdargaud commentedon Jul 14, 2017
As a dirty workaround I am currently using somehting along those lines :
At least I don't have "thumb_up Nice!" displayed and can work with it until it's fixed (be aware, it does seem to take some time to evaluate the template when opening the select, and the raw html is shown for a short period of time).
feat(select): add ability to customize the select trigger
feat(select): add ability to customize the select trigger
feat(select): add ability to customize the select trigger (#3341)
LayZeeDK commentedon Nov 22, 2018
For future reference, you can use the
<mat-select-trigger>to change the display of the selected value.It was added by @crisbeto in Angular Material version 2 beta 10.
angular-automatic-lock-bot commentedon Sep 10, 2019
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.