Skip to content

Commit 28466ab

Browse files
committed
Merge pull request angular-ui#256 from JeffGreat/master
Add possibility to find value according to a property of the model
2 parents 1af3a56 + b8bcd8a commit 28466ab

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: src/select.js

+7
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,13 @@
952952
for (var p = list.length - 1; p >= 0; p--) {
953953
locals[$select.parserResult.itemName] = list[p];
954954
result = $select.parserResult.modelMapper(scope, locals);
955+
if($select.parserResult.trackByExp){
956+
var matches = /\.(.+)/.exec($select.parserResult.trackByExp);
957+
if(matches.length>0 && result[matches[1]] == value[matches[1]]){
958+
resultMultiple.unshift(list[p]);
959+
return true;
960+
}
961+
}
955962
if (result == value){
956963
resultMultiple.unshift(list[p]);
957964
return true;

Diff for: test/select.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ describe('ui-select tests', function() {
158158

159159
expect(getMatchLabel(el)).toEqual('Adam');
160160
});
161+
162+
it('should correctly render initial state with track by feature', function() {
163+
var el = compileTemplate(
164+
'<ui-select ng-model="selection.selected"> \
165+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
166+
<ui-select-choices repeat="person in people | filter: $select.search track by person.name"> \
167+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
168+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
169+
</ui-select-choices> \
170+
</ui-select>'
171+
);
172+
scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 };
173+
scope.$digest();
174+
expect(getMatchLabel(el)).toEqual('Samantha');
175+
});
161176

162177
it('should display the choices when activated', function() {
163178
var el = createUiSelect();

0 commit comments

Comments
 (0)