diff --git a/src/select.js b/src/select.js index 91923a165..fa13e09f8 100644 --- a/src/select.js +++ b/src/select.js @@ -943,6 +943,13 @@ for (var p = list.length - 1; p >= 0; p--) { locals[$select.parserResult.itemName] = list[p]; result = $select.parserResult.modelMapper(scope, locals); + if($select.parserResult.trackByExp){ + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if(matches.length>0 && result[matches[1]] == value[matches[1]]){ + resultMultiple.unshift(list[p]); + return true; + } + } if (result == value){ resultMultiple.unshift(list[p]); return true; diff --git a/test/select.spec.js b/test/select.spec.js index 37f656a18..0ebb1f38f 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -157,6 +157,21 @@ describe('ui-select tests', function() { expect(getMatchLabel(el)).toEqual('Adam'); }); + + it('should correctly render initial state with track by feature', function() { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 }; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); it('should display the choices when activated', function() { var el = createUiSelect();