@@ -174,7 +174,8 @@ angular.module('material.components.select', [
174
174
* </div>
175
175
* </hljs>
176
176
*/
177
- function SelectDirective ( $mdSelect , $mdUtil , $mdConstant , $mdTheming , $mdAria , $parse ) {
177
+ function SelectDirective ( $mdSelect , $mdUtil , $mdConstant , $mdTheming , $mdAria , $parse , $sce ,
178
+ $injector ) {
178
179
var keyCodes = $mdConstant . KEY_CODE ;
179
180
var NAVIGATION_KEYS = [ keyCodes . SPACE , keyCodes . ENTER , keyCodes . UP_ARROW , keyCodes . DOWN_ARROW ] ;
180
181
@@ -337,17 +338,41 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
337
338
mdSelectCtrl . setLabelText = function ( text ) {
338
339
mdSelectCtrl . setIsPlaceholder ( ! text ) ;
339
340
340
- if ( attr . mdSelectedText ) {
341
- text = $parse ( attr . mdSelectedText ) ( scope ) ;
342
- } else {
341
+ // Whether the select label has been given via user content rather than the internal
342
+ // template of <md-option>
343
+ var isSelectLabelFromUser = false ;
344
+
345
+ if ( attr . mdSelectedText && attr . mdSelectedHtml ) {
346
+ throw Error ( 'md-select cannot have both `md-selected-text` and `md-selected-html`' ) ;
347
+ }
348
+
349
+ if ( attr . mdSelectedText || attr . mdSelectedHtml ) {
350
+ text = $parse ( attr . mdSelectedText || attr . mdSelectedHtml ) ( scope ) ;
351
+ isSelectLabelFromUser = true ;
352
+ } else if ( ! text ) {
343
353
// Use placeholder attribute, otherwise fallback to the md-input-container label
344
354
var tmpPlaceholder = attr . placeholder ||
345
355
( containerCtrl && containerCtrl . label ? containerCtrl . label . text ( ) : '' ) ;
346
- text = text || tmpPlaceholder || '' ;
356
+
357
+ text = tmpPlaceholder || '' ;
358
+ isSelectLabelFromUser = true ;
347
359
}
348
360
349
361
var target = valueEl . children ( ) . eq ( 0 ) ;
350
- target . html ( text ) ;
362
+
363
+ if ( attr . mdSelectedHtml ) {
364
+ if ( ! $injector . has ( '$sanitize' ) ) {
365
+ throw Error ( 'The ngSanitize module must be loaded in order to use ' +
366
+ 'md-treat-selected-text-as-html.' ) ;
367
+ }
368
+
369
+ target . html ( $sce . getTrustedHtml ( text ) ) ;
370
+ } else if ( isSelectLabelFromUser ) {
371
+ target . text ( text ) ;
372
+ } else {
373
+ // If we've reached this point, the text is not user-provided.
374
+ target . html ( text ) ;
375
+ }
351
376
} ;
352
377
353
378
mdSelectCtrl . setIsPlaceholder = function ( isPlaceholder ) {
0 commit comments