diff --git a/src/select.js b/src/select.js index d7fa97809..c46fde87c 100644 --- a/src/select.js +++ b/src/select.js @@ -599,14 +599,11 @@ .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); - transcludeFn(function(clone) { - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - rowsInner.append(clone); - $compile(element)(scope); - }); + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend scope.$watch('$select.search', function() { $select.activeIndex = 0; @@ -622,7 +619,15 @@ } }; }]) - + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) .directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { return { restrict: 'EA', diff --git a/test/select.spec.js b/test/select.spec.js index 0379ddf15..1a6d09b7f 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -510,4 +510,46 @@ describe('ui-select tests', function() { }); + it('should append/transclude content (with correct scope) that users add at tag', function () { + + var el = compileTemplate( + ' \ + \ + {{$select.selected.name}}\ + {{$select.selected.name | uppercase}}\ + \ + \ +
\ +
\ +
' + ); + + clickItem(el, 'Samantha'); + expect(getMatchLabel(el).trim()).toEqual('Samantha'); + + clickItem(el, 'Wladimir'); + expect(getMatchLabel(el).trim()).not.toEqual('Wladimir'); + expect(getMatchLabel(el).trim()).toEqual('WLADIMIR'); + + }); + it('should append/transclude content (with correct scope) that users add at tag', function () { + + var el = compileTemplate( + ' \ + \ + \ + \ +
\ +
\ + I should appear only once\ +
\ +
\ +
' + ); + + expect($(el).find('.only-once').length).toEqual(1); + + + }); + });