@@ -418,6 +418,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
418
418
selectContainer [ 0 ] . setAttribute ( 'class' , value ) ;
419
419
}
420
420
selectMenuCtrl = selectContainer . find ( 'md-select-menu' ) . controller ( 'mdSelectMenu' ) ;
421
+ selectMenuCtrl . init ( ngModelCtrl , attr . ngModel ) ;
421
422
}
422
423
423
424
function handleKeypress ( e ) {
@@ -452,6 +453,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
452
453
element : selectContainer ,
453
454
target : element [ 0 ] ,
454
455
preserveElement : true ,
456
+ parent : element ,
455
457
hasBackdrop : true ,
456
458
loadingAsync : attr . mdOnOpen ? scope . $eval ( attr . mdOnOpen ) || true : false
457
459
} ) . finally ( function ( ) {
@@ -468,7 +470,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
468
470
469
471
return {
470
472
restrict : 'E' ,
471
- require : [ 'mdSelectMenu' , '^ngModel' ] ,
473
+ require : [ 'mdSelectMenu' ] ,
472
474
scope : true ,
473
475
controller : SelectMenuController ,
474
476
link : { pre : preLink }
@@ -478,12 +480,10 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
478
480
// its child options run postLink.
479
481
function preLink ( scope , element , attr , ctrls ) {
480
482
var selectCtrl = ctrls [ 0 ] ;
481
- var ngModel = ctrls [ 1 ] ;
482
483
483
484
$mdTheming ( element ) ;
484
485
element . on ( 'click' , clickListener ) ;
485
486
element . on ( 'keypress' , keyListener ) ;
486
- if ( ngModel ) selectCtrl . init ( ngModel ) ;
487
487
488
488
function keyListener ( e ) {
489
489
if ( e . keyCode == 13 || e . keyCode == 32 ) {
@@ -551,7 +551,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
551
551
552
552
// watchCollection on the model because by default ngModel only watches the model's
553
553
// reference. This allowed the developer to also push and pop from their array.
554
- $scope . $watchCollection ( $attrs . ngModel , function ( value ) {
554
+ $scope . $watchCollection ( self . modelBinding , function ( value ) {
555
555
if ( validateArray ( value ) ) renderMultiple ( value ) ;
556
556
self . ngModel . $setPristine ( ) ;
557
557
} ) ;
@@ -598,8 +598,9 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
598
598
}
599
599
} ;
600
600
601
- self . init = function ( ngModel ) {
601
+ self . init = function ( ngModel , binding ) {
602
602
self . ngModel = ngModel ;
603
+ self . modelBinding = binding ;
603
604
604
605
// Allow users to provide `ng-model="foo" ng-model-options="{trackBy: 'foo.id'}"` so
605
606
// that we can properly compare objects set on the model to the available options
@@ -782,7 +783,15 @@ function OptionDirective($mdButtonInkRipple, $mdUtil) {
782
783
$mdButtonInkRipple . attach ( scope , element ) ;
783
784
configureAria ( ) ;
784
785
785
- function setOptionValue ( newValue , oldValue ) {
786
+ function setOptionValue ( newValue , oldValue , prevAttempt ) {
787
+ if ( ! selectCtrl . hashGetter ) {
788
+ if ( ! prevAttempt ) {
789
+ scope . $$postDigest ( function ( ) {
790
+ setOptionValue ( newValue , oldValue , true ) ;
791
+ } ) ;
792
+ }
793
+ return ;
794
+ }
786
795
var oldHashKey = selectCtrl . hashGetter ( oldValue , scope ) ;
787
796
var newHashKey = selectCtrl . hashGetter ( newValue , scope ) ;
788
797
@@ -1238,7 +1247,7 @@ function SelectProvider($$interimElementProvider) {
1238
1247
* trigger the [optional] user-defined expression
1239
1248
*/
1240
1249
function announceClosed ( opts ) {
1241
- var mdSelect = opts . target . controller ( 'mdSelect' ) ;
1250
+ var mdSelect = opts . selectEl . controller ( 'mdSelect' ) ;
1242
1251
if ( mdSelect ) {
1243
1252
var menuController = opts . selectEl . controller ( 'mdSelectMenu' ) ;
1244
1253
mdSelect . setLabelText ( menuController . selectedLabels ( ) ) ;
@@ -1253,7 +1262,7 @@ function SelectProvider($$interimElementProvider) {
1253
1262
function calculateMenuPositions ( scope , element , opts ) {
1254
1263
var
1255
1264
containerNode = element [ 0 ] ,
1256
- targetNode = opts . target [ 0 ] . children [ 0 ] , // target the label
1265
+ targetNode = opts . target [ 0 ] . children [ 1 ] , // target the label
1257
1266
parentNode = $document [ 0 ] . body ,
1258
1267
selectNode = opts . selectEl [ 0 ] ,
1259
1268
contentNode = opts . contentEl [ 0 ] ,
0 commit comments