@@ -738,6 +738,15 @@ describe('<md-select>', function() {
738
738
expect ( selectedOptions ( el ) . length ) . toBe ( 0 ) ;
739
739
} ) ;
740
740
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
+
741
750
it ( 'supports circular references' , function ( ) {
742
751
var opts = [ { id : 1 } , { id : 2 } ] ;
743
752
opts [ 0 ] . refs = opts [ 1 ] ;
@@ -1688,13 +1697,13 @@ describe('<md-select>', function() {
1688
1697
} ) ;
1689
1698
}
1690
1699
1691
- function setupSelect ( attrs , options , skipLabel , scope , optCompileOpts ) {
1700
+ function setupSelect ( attrs , options , skipLabel , scope , optCompileOpts , ngSelectedExpression ) {
1692
1701
var el ;
1693
1702
var template = '' +
1694
1703
'<md-input-container>' +
1695
1704
( skipLabel ? '' : '<label>Label</label>' ) +
1696
1705
'<md-select ' + ( attrs || '' ) + '>' +
1697
- optTemplate ( options , optCompileOpts ) +
1706
+ optTemplate ( options , optCompileOpts , ngSelectedExpression ) +
1698
1707
'</md-select>' +
1699
1708
'</md-input-container>' ;
1700
1709
@@ -1713,13 +1722,21 @@ describe('<md-select>', function() {
1713
1722
return toReturn ;
1714
1723
}
1715
1724
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 ) {
1717
1732
var optionsTpl = '' ;
1733
+ var ngSelectedTemplate = ngSelectedExpression ? ' ng-selected="' + ngSelectedExpression + '"' : '' ;
1718
1734
1719
1735
if ( angular . isArray ( options ) ) {
1720
1736
$rootScope . $$values = options ;
1721
1737
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>' ;
1723
1740
} else if ( angular . isString ( options ) ) {
1724
1741
optionsTpl = options ;
1725
1742
}
@@ -1739,7 +1756,7 @@ describe('<md-select>', function() {
1739
1756
}
1740
1757
1741
1758
function openSelect ( el ) {
1742
- if ( el [ 0 ] . nodeName != 'MD-SELECT' ) {
1759
+ if ( el [ 0 ] . nodeName !== 'MD-SELECT' ) {
1743
1760
el = el . find ( 'md-select' ) ;
1744
1761
}
1745
1762
try {
0 commit comments