Material: select: trackBy does not work with virtual-repeated options

Created on 8 Jul 2016  路  5Comments  路  Source: angular/material

Actual Behavior:

  • What is the issue? * Using the ng-model-options= {trackBy: '$value.propertyName'} does not work as expected on initialization or when the scope model changes outside of the mdSelect directive.
  • What is the expected behavior? The codepen has a angular only demo right next to the mdSelect bug demo that accurately behaves as expected. The expected behaviour is that providing the ng-model-options= {trackBy: '$value.propertyName'} causes the mdSelect to display the selected value in the select container.

CodePen (or steps to reproduce the issue): *

  • CodePen Demo which shows your issue: https://codepen.io/anon/pen/kXoRrR
  • Details: On initialization the proper variable is not selected. Classic angular options in select works as expected for an example. Also, applying a new value outside of the select container does not apply the selected value in the select view. Note, that all the values are correct in the background; however, it does not display the correct value unless physically selected in the select container. Note that all these operations are within the same scope.

Angular Versions: *

  • Angular Version: 1.5.5 +
  • Angular Material Version: 1.0.5, 1.0.9

Additional Information:

  • Browser Type: * Chrome, Firefox, Internet Explorer
  • Browser Version: * Chrome: 51.0.2704.106 m, IE: 11, FireFox: 47.0
  • OS: * Windows 7
  • Stack Traces: N/A
important investigation bug

All 5 comments

Are there any updates for this bug?

Just to make sure I didn't get confused I also tried to have trackBy written as thus:

  • {trackBy: 'option.id'}
  • {trackBy: option.id}
  • {trackBy: '$value.id'} (documented)
  • {trackBy: $value.id}
  • {trackBy: 'id'}
  • {trackBy: id}

All did not work. Also, I know that the last two are not valid, but I tried them anyways.

I updated it because the original issue is slightly off. This behaviour only occurs inside of the mdVirtualRepeatContainer. Removing the md-virtual-repeat-container element dismisses the issue. Although, I have felt this is being ignored either way. I have updated the title accordingly. However, I decided to keep an updated record since the known performance issue workarounds usually suggest using a virtual repeat.

Updated the CodePen to AngularJS Material 1.1.21, but ran into the options not displaying due to https://github.com/angular/material/issues/10868.

Updated title as md-virtual-repeat does not support trackBy, but md-select does.

Was this page helpful?
0 / 5 - 0 ratings