@@ -738,6 +738,15 @@ describe('<md-select>', function() {
738738 expect ( selectedOptions ( el ) . length ) . toBe ( 0 ) ;
739739 } ) ;
740740
741+ it ( 'supports ng-selected on md-options' , function ( ) {
742+ var el = setupSelect ( 'ng-model="$root.model"' , [ 'a' , 'b' , 'c' ] , false , $rootScope , null ,
743+ '$index === 2' ) ;
744+
745+ expect ( selectedOptions ( el ) . length ) . toBe ( 1 ) ;
746+ expect ( el . find ( 'md-option' ) . eq ( 2 ) . attr ( 'selected' ) ) . toBe ( 'selected' ) ;
747+ expect ( $rootScope . model ) . toBe ( 'c' ) ;
748+ } ) ;
749+
741750 it ( 'supports circular references' , function ( ) {
742751 var opts = [ { id : 1 } , { id : 2 } ] ;
743752 opts [ 0 ] . refs = opts [ 1 ] ;
@@ -1688,13 +1697,13 @@ describe('<md-select>', function() {
16881697 } ) ;
16891698 }
16901699
1691- function setupSelect ( attrs , options , skipLabel , scope , optCompileOpts ) {
1700+ function setupSelect ( attrs , options , skipLabel , scope , optCompileOpts , ngSelectedExpression ) {
16921701 var el ;
16931702 var template = '' +
16941703 '<md-input-container>' +
16951704 ( skipLabel ? '' : '<label>Label</label>' ) +
16961705 '<md-select ' + ( attrs || '' ) + '>' +
1697- optTemplate ( options , optCompileOpts ) +
1706+ optTemplate ( options , optCompileOpts , ngSelectedExpression ) +
16981707 '</md-select>' +
16991708 '</md-input-container>' ;
17001709
@@ -1713,13 +1722,21 @@ describe('<md-select>', function() {
17131722 return toReturn ;
17141723 }
17151724
1716- function optTemplate ( options , compileOpts ) {
1725+ /**
1726+ * @param {any[]= } options Array of option values to create md-options from
1727+ * @param {object= } compileOpts
1728+ * @param {object= } ngSelectedExpression If defined, sets the expression used by ng-selected.
1729+ * @return {string } template containing the generated md-options
1730+ */
1731+ function optTemplate ( options , compileOpts , ngSelectedExpression ) {
17171732 var optionsTpl = '' ;
1733+ var ngSelectedTemplate = ngSelectedExpression ? ' ng-selected="' + ngSelectedExpression + '"' : '' ;
17181734
17191735 if ( angular . isArray ( options ) ) {
17201736 $rootScope . $$values = options ;
17211737 var renderValueAs = compileOpts ? compileOpts . renderValueAs || 'value' : 'value' ;
1722- optionsTpl = '<md-option ng-repeat="value in $$values" ng-value="value"><div class="md-text">{{' + renderValueAs + '}}</div></md-option>' ;
1738+ optionsTpl = '<md-option ng-repeat="value in $$values" ng-value="value"' + ngSelectedTemplate + '>' +
1739+ '<div class="md-text">{{' + renderValueAs + '}}</div></md-option>' ;
17231740 } else if ( angular . isString ( options ) ) {
17241741 optionsTpl = options ;
17251742 }
@@ -1739,7 +1756,7 @@ describe('<md-select>', function() {
17391756 }
17401757
17411758 function openSelect ( el ) {
1742- if ( el [ 0 ] . nodeName != 'MD-SELECT' ) {
1759+ if ( el [ 0 ] . nodeName !== 'MD-SELECT' ) {
17431760 el = el . find ( 'md-select' ) ;
17441761 }
17451762 try {
0 commit comments