From 2cc669a7e09534c83a186b27ea461ba5c6ac0313 Mon Sep 17 00:00:00 2001 From: JeffGreat Date: Fri, 3 Oct 2014 18:25:57 +0200 Subject: [PATCH 1/2] Add possibility to find value according to a property of the model I needed that feature to preload existing model objects that are not in the source list. The comparison is made upon the property setted via the "track by" of the repeater. --- src/select.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/select.js b/src/select.js index abbdf8e22..ada778c74 100644 --- a/src/select.js +++ b/src/select.js @@ -606,6 +606,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; From 6d6baac07e87562e54c857674a84938cff6ea62f Mon Sep 17 00:00:00 2001 From: JeffGreat Date: Thu, 13 Nov 2014 11:42:51 +0100 Subject: [PATCH 2/2] Update select.spec.js --- test/select.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/select.spec.js b/test/select.spec.js index f2f4f2690..1a1fbb04e 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -142,6 +142,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();