Skip to content

Commit

Permalink
fix: make compatible with Angular 1.5 and non-cached templates
Browse files Browse the repository at this point in the history
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 angular-ui#224.

Closes angular-ui#1422
Closes angular-ui#1356
Closes angular-ui#1325
Closes angular-ui#1239
  • Loading branch information
Narretz committed Feb 12, 2016
1 parent 88aebde commit 0e85670
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/uiSelectChoicesDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ uis.directive('uiSelectChoices',
replace: true,
transclude: true,
templateUrl: function(tElement) {
// Needed so the uiSelect can detect the transcluded content
tElement.addClass('ui-select-choices');

// Gets theme attribute from parent (ui-select)
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
return theme + '/choices.tpl.html';
Expand Down
3 changes: 3 additions & 0 deletions src/uiSelectMatchDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
replace: true,
transclude: true,
templateUrl: function(tElement) {
// Needed so the uiSelect can detect the transcluded content
tElement.addClass('ui-select-match');

// Gets theme attribute from parent (ui-select)
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
var multi = tElement.parent().attr('multiple');
Expand Down
1 change: 1 addition & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ describe('ui-select tests', function() {
expect(function() {
compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match></ui-select-match> \
<ui-select-choices></ui-select-choices> \
</ui-select>'
);
Expand Down

0 comments on commit 0e85670

Please sign in to comment.