Material: mdSelect trackBy not working

Created on 29 Dec 2016  路  5Comments  路  Source: angular/material

When adding the ngModeOptions -> {trackBy: '$value.id'}
The select never shows the current selection

<md-select ng-model="vm.move.organization"
                       ng-disabled="!vm.canEdit"
                       required
                       ng-change="vm.organizationChanged()"
                       ng-model-options="{trackBy: '$value.id'}">
              <md-option ng-value="organization"
                         ng-repeat="organization in vm.organizations">
                {{organization.organizationData.name}}
              </md-option>
</md-select>
Angular 1.6 support

Most helpful comment

There is a bug with angular 1.6.x now. If you use angular 1.5.9, everything is fine.

CodePen Demo which works with angular 1.5.9: http://codepen.io/anon/pen/egObNW
CodePen Demo which does not work with angular 1.6.1: http://codepen.io/anon/pen/mRbaVg

Versions

Angular Material Version: 1.1.1

Bug Details

There is an if condition which determines whether ngModel.$options has trackBy value in init function of SelectMenuController. With angular 1.6.x, this condition does not work properly because trackBy value looks under ngModel.$options.$$options

screenshot

All 5 comments

There is a bug with angular 1.6.x now. If you use angular 1.5.9, everything is fine.

CodePen Demo which works with angular 1.5.9: http://codepen.io/anon/pen/egObNW
CodePen Demo which does not work with angular 1.6.1: http://codepen.io/anon/pen/mRbaVg

Versions

Angular Material Version: 1.1.1

Bug Details

There is an if condition which determines whether ngModel.$options has trackBy value in init function of SelectMenuController. With angular 1.6.x, this condition does not work properly because trackBy value looks under ngModel.$options.$$options

screenshot

Well thanks @tugrulelmas :D

@tugrulelmas @germanamz it's not a bug, it's a breaking change in angular.

According to https://github.com/angular/angular.js/commit/296cfce40c25e9438bfa46a0eb27240707a10ffa we have to access the option with ngModel.$options.getOption('trackBy').

@DevVersion - Can you help resolve this one: ngM1 + ng1.6 + ngModel

This has been fixed with SHA a73ab43c437ec7468d51da54f159b9f2845ec07b. And all tests pass on Travis. Closing (again) as fixed.

Was this page helpful?
0 / 5 - 0 ratings