Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 238a428

Browse files
committed
Merge pull request #611 from swalters/parentNgModel
fix(ngModel) Allow uiSelect ngModel to populate from parent directive.
2 parents 69d6244 + 27824c5 commit 238a428

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@
915915
},
916916
replace: true,
917917
transclude: true,
918-
require: ['uiSelect', 'ngModel'],
918+
require: ['uiSelect', '^ngModel'],
919919
scope: true,
920920

921921
controller: 'uiSelectCtrl',

test/select.spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,28 @@ describe('ui-select tests', function() {
1515
Escape: 27
1616
};
1717

18-
beforeEach(module('ngSanitize', 'ui.select'));
18+
//create a directive that wraps ui-select
19+
angular.module('wrapperDirective',['ui.select']);
20+
angular.module('wrapperDirective').directive('wrapperUiSelect', function(){
21+
return {
22+
restrict: 'EA',
23+
template: '<ui-select> \
24+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
25+
<ui-select-choices repeat="person in people | filter: $select.search"> \
26+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
27+
</ui-select-choices> \
28+
</ui-select>',
29+
require: 'ngModel',
30+
scope: true,
31+
32+
link: function (scope, element, attrs, ctrl) {
33+
34+
}
35+
}
36+
37+
});
38+
39+
beforeEach(module('ngSanitize', 'ui.select', 'wrapperDirective'));
1940
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_) {
2041
$rootScope = _$rootScope_;
2142
scope = $rootScope.$new();
@@ -186,6 +207,13 @@ describe('ui-select tests', function() {
186207
expect(getMatchLabel(el)).toEqual('Samantha');
187208
});
188209

210+
it('should utilize wrapper directive ng-model', function() {
211+
var el = compileTemplate('<wrapper-ui-select ng-model="selection.selected"/>');
212+
scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 };
213+
scope.$digest();
214+
expect($(el).find('.ui-select-container > .ui-select-match > button:first > span[ng-transclude]:not(.ng-hide)').text()).toEqual('Samantha');
215+
});
216+
189217
it('should display the choices when activated', function() {
190218
var el = createUiSelect();
191219

0 commit comments

Comments
 (0)