-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support template content for selected value in md-select #2275
Comments
Use this to display the formatted html: |
That isn't the issue. |
The html is stripped here: get viewValue(): string { 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 |
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. |
Adds the `md-select-label` directive which allows users to customize the selected value. E.g. it is now possible to do something like this, if the user wanted to reverse the selected label for some reason: ```ts <md-select placeholder="Food" [formControl]="control" #select="mdSelect"> <md-select-label> {{ select.selected?.viewValue.split('').reverse().join('') }} </md-select-label> <md-option *ngFor="let food of foods" [value]="food.value"> {{ food.viewValue }} </md-option> </md-select> ``` Fixes angular#2275.
@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: |
This is the intended usage @andreasrueedlinger: <md-select #select="mdSelect">
<md-select-label>
{{ select.selected?.viewValue }}
</md-select-label>
<!-- options go here -->
</md-select> |
@crisbeto but that does not fix the problem adressed in this issue, namely that the label does not support Html! |
You can put any HTML you want inside the |
That's not what he meant I think. When you have.. <md-option>
<img src="whatever.jpg" /> Whatever
</md-option> ..and you select it, the selected content won't be |
But in your example you use normal binding and <md-select placeholder="Feedback" [formControl]="control" #select="mdSelect">
<md-select-label [innerHtml]="select.selected?._getHostElement().innerHTML"></md-select-label>
<md-option value="good">
<md-icon>thumb_up</md-icon> Nice!
</md-option>
<md-option value="bad">
<md-icon>thumb_down</md-icon> Bad!
</md-option>
</md-select> |
That's true, but if we just dumped the |
There should be a straightforward way to do it nevertheless. It's pretty limiting when you know the values are safe. |
Also the way it works currently is that if I have.. <md-option>
<span class="in-a-circle-with-background-and-uppercase">un</span>User Name
</md-option> ..the selected value will be |
You can still use |
XSS should not be a problem since Angular sanitizes the input to |
support for multiple selection ? |
Good thing is that I think this could be used for #2722 (comment) |
Is there any workaround with 2.0.0-beta.3 ? |
Any news about this? |
An updated plunker for the problem can be found here: http://plnkr.co/edit/vuF3Pz7UHDXERXZbtiIK?p=preview |
Any news about this? |
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). |
Adds the `md-select-trigger` directive which allows users to customize the selected value. E.g. it is now possible to do something like this, if the user wanted to reverse the selected label for some reason: ```ts <md-select placeholder="Food" [formControl]="control" #select="mdSelect"> <md-select-trigger> {{ select.selected?.viewValue.split('').reverse().join('') }} </md-select-trigger> <md-option *ngFor="let food of foods" [value]="food.value"> {{ food.viewValue }} </md-option> </md-select> ``` Fixes angular#2275.
Adds the `md-select-trigger` directive which allows users to customize the selected value. E.g. it is now possible to do something like this, if the user wanted to reverse the selected label for some reason: ```ts <md-select placeholder="Food" [formControl]="control" #select="mdSelect"> <md-select-trigger> {{ select.selected?.viewValue.split('').reverse().join('') }} </md-select-trigger> <md-option *ngFor="let food of foods" [value]="food.value"> {{ food.viewValue }} </md-option> </md-select> ``` Fixes #2275.
Adds the `md-select-trigger` directive which allows users to customize the selected value. E.g. it is now possible to do something like this, if the user wanted to reverse the selected label for some reason: ```ts <md-select placeholder="Food" [formControl]="control" #select="mdSelect"> <md-select-trigger> {{ select.selected?.viewValue.split('').reverse().join('') }} </md-select-trigger> <md-option *ngFor="let food of foods" [value]="food.value"> {{ food.viewValue }} </md-option> </md-select> ``` Fixes #2275.
For future reference, you can use the It was added by @crisbeto in Angular Material version 2 beta 10. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
bug
What is the expected behavior?
Selected option of a md-select supports html-tags
What is the current behavior?
Selected option of a md-select doesn't supports html-tags
What are the steps to reproduce?
See http://plnkr.co/edit/QJUCobw9yFcu1l1WtpOR?p=preview
Open the md-select.
In the dropdown the option supports html tags
Select the option
All html tags are stripped of the shown value in the md-select.
The text was updated successfully, but these errors were encountered: