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

Commit 0e85670

Browse files
committed
fix: make compatible with Angular 1.5 and non-cached templates
In Angular 1.5, transcluded content is compiled lazily. For uiSelect that means the clone in the transclude function is not compiled and linked yet, so uiSelect cannot detect the match and choices elements by their classnames, because they haven't been set yet (which happens by replacing the elements with the templates). However, the templateUrl function is executed at this point, so we can use it to add the class names to the directive elements. On another note, this behavior also affected versions earlier than 1.5.0-beta.2, when the template of ui-select-match or ui-select-choices wasn't cached. In that case, the async compilation of the template would mean also that the clone in the transclude function wasn't compiled yet, and so the classes wouldn't be set either. This might be the cause of the error described in issue #224. Closes #1422 Closes #1356 Closes #1325 Closes #1239
1 parent 88aebde commit 0e85670

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/uiSelectChoicesDirective.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ uis.directive('uiSelectChoices',
88
replace: true,
99
transclude: true,
1010
templateUrl: function(tElement) {
11+
// Needed so the uiSelect can detect the transcluded content
12+
tElement.addClass('ui-select-choices');
13+
1114
// Gets theme attribute from parent (ui-select)
1215
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
1316
return theme + '/choices.tpl.html';

src/uiSelectMatchDirective.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
55
replace: true,
66
transclude: true,
77
templateUrl: function(tElement) {
8+
// Needed so the uiSelect can detect the transcluded content
9+
tElement.addClass('ui-select-match');
10+
811
// Gets theme attribute from parent (ui-select)
912
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
1013
var multi = tElement.parent().attr('multiple');

test/select.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ describe('ui-select tests', function() {
967967
expect(function() {
968968
compileTemplate(
969969
'<ui-select ng-model="selection.selected"> \
970+
<ui-select-match></ui-select-match> \
970971
<ui-select-choices></ui-select-choices> \
971972
</ui-select>'
972973
);

0 commit comments

Comments
 (0)