@@ -248,15 +248,17 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
248248 var getGroupName = function ( value , key ) { return callExpression ( groupByFn , value , key ) || '' ; } ;
249249 var getValues = function ( ) { return valuesFn ( scope ) || [ ] ; } ;
250250 var getDisplayLabel = function ( value , key ) { return callExpression ( displayFn , value , key ) ; } ;
251- var getTrackByValue = function ( value , key ) {
252- return '' + callExpression ( trackByFn , value , key ) ;
253- } ;
254251 var getViewValue = function ( value , key ) {
255252 return ( key === '?' ) ? undefined :
256253 ( key === '' ) ? null :
257254 callExpression ( viewValueFn , value , key ) ;
258255 } ;
259256
257+ // Get the value that represents the object in the options collection
258+ var getTrackByValue = trackByFn ? function ( value , key ) {
259+ return '' + callExpression ( trackByFn , value , key ) ;
260+ } : function ( value , key ) { return hashKey ( value ) ; } ;
261+
260262 // Get the value that is assigned to and compared to the value of the options
261263 var getSelectValue = trackByFn ? getTrackByValue : function ( value , key ) {
262264 return hashKey ( getViewValue ( value , key ) ) ;
@@ -304,11 +306,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
304306 items : optionItems ,
305307 selectValueMap : selectValueMap ,
306308 getOptionFromViewValue : function ( value ) {
307- if ( ! ! trackBy ) {
308- return selectValueMap . get ( getTrackByValue ( value ) ) ;
309- } else {
310- return selectValueMap . get ( hashKey ( value ) ) ;
311- }
309+ return selectValueMap . get ( getTrackByValue ( value ) ) ;
312310 }
313311 } ;
314312 }
0 commit comments