@@ -75,7 +75,12 @@ angular.module('material.components.select', [
75
75
* @param {expression= } md-on-open Expression to be evaluated when opening the select.
76
76
* Will hide the select options and show a spinner until the evaluated promise resolves.
77
77
* @param {expression= } md-selected-text Expression to be evaluated that will return a string
78
- * to be displayed as a placeholder in the select input box when it is closed.
78
+ * to be displayed as a placeholder in the select input box when it is closed. The value
79
+ * will be treated as *text* (not html).
80
+ * @param {expression= } md-selected-html Expression to be evaluated that will return a string
81
+ * to be displayed as a placeholder in the select input box when it is closed. The value
82
+ * will be treated as *html*. The value must either be explicitly marked as trustedHtml or
83
+ * the ngSanitize module must be loaded.
79
84
* @param {string= } placeholder Placeholder hint text.
80
85
* @param md-no-asterisk {boolean=} When set to true, an asterisk will not be appended to the
81
86
* floating label. **Note:** This attribute is only evaluated once; it is not watched.
@@ -174,7 +179,8 @@ angular.module('material.components.select', [
174
179
* </div>
175
180
* </hljs>
176
181
*/
177
- function SelectDirective ( $mdSelect , $mdUtil , $mdConstant , $mdTheming , $mdAria , $parse ) {
182
+ function SelectDirective ( $mdSelect , $mdUtil , $mdConstant , $mdTheming , $mdAria , $parse , $sce ,
183
+ $injector ) {
178
184
var keyCodes = $mdConstant . KEY_CODE ;
179
185
var NAVIGATION_KEYS = [ keyCodes . SPACE , keyCodes . ENTER , keyCodes . UP_ARROW , keyCodes . DOWN_ARROW ] ;
180
186
@@ -337,17 +343,39 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
337
343
mdSelectCtrl . setLabelText = function ( text ) {
338
344
mdSelectCtrl . setIsPlaceholder ( ! text ) ;
339
345
340
- if ( attr . mdSelectedText ) {
341
- text = $parse ( attr . mdSelectedText ) ( scope ) ;
342
- } else {
346
+ // Whether the select label has been given via user content rather than the internal
347
+ // template of <md-option>
348
+ var isSelectLabelFromUser = false ;
349
+
350
+ if ( attr . mdSelectedText && attr . mdSelectedHtml ) {
351
+ throw Error ( 'md-select cannot have both `md-selected-text` and `md-selected-html`' ) ;
352
+ }
353
+
354
+ if ( attr . mdSelectedText || attr . mdSelectedHtml ) {
355
+ text = $parse ( attr . mdSelectedText || attr . mdSelectedHtml ) ( scope ) ;
356
+ isSelectLabelFromUser = true ;
357
+ } else if ( ! text ) {
343
358
// Use placeholder attribute, otherwise fallback to the md-input-container label
344
359
var tmpPlaceholder = attr . placeholder ||
345
360
( containerCtrl && containerCtrl . label ? containerCtrl . label . text ( ) : '' ) ;
346
- text = text || tmpPlaceholder || '' ;
361
+
362
+ text = tmpPlaceholder || '' ;
363
+ isSelectLabelFromUser = true ;
347
364
}
348
365
349
366
var target = valueEl . children ( ) . eq ( 0 ) ;
350
- target . html ( text ) ;
367
+
368
+ if ( attr . mdSelectedHtml ) {
369
+ // Using getTrustedHtml will run the content through $sanitize if it is not already
370
+ // explicitly trusted. If the ngSanitize module is not loaded, this will
371
+ // *correctly* throw an sce error.
372
+ target . html ( $sce . getTrustedHtml ( text ) ) ;
373
+ } else if ( isSelectLabelFromUser ) {
374
+ target . text ( text ) ;
375
+ } else {
376
+ // If we've reached this point, the text is not user-provided.
377
+ target . html ( text ) ;
378
+ }
351
379
} ;
352
380
353
381
mdSelectCtrl . setIsPlaceholder = function ( isPlaceholder ) {
0 commit comments