From 03446c56335d5ee0970f9730af215fea1dd53f48 Mon Sep 17 00:00:00 2001 From: Christoph Herbst Date: Tue, 18 Mar 2014 14:48:57 +0100 Subject: [PATCH] fix(typeahead): $compile match template after adding to DOM --- src/typeahead/test/typeahead.spec.js | 20 ++++++++++++++++++++ src/typeahead/typeahead.js | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 8f2c7323c1..7b54ab7b8f 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -17,6 +17,13 @@ describe('typeahead tests', function () { } }; }); + $compileProvider.directive('childDirective', function () { + return { + restrict: 'A', + require: '^parentDirective', + link: function(scope, element, attrs, ctrl) {} + }; + }); })); beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, _$timeout_, $sniffer) { $scope = _$rootScope_; @@ -308,6 +315,19 @@ describe('typeahead tests', function () { expect(findMatches(element).eq(0).find('p').text()).toEqual('0 Alaska'); })); + it('should support directives which require controllers in custom templates for matched items', inject(function ($templateCache) { + + $templateCache.put('custom.html', '

{{ index }} {{ match.label }}

'); + + var element = prepareInputEl('
'); + + element.data('$parentDirectiveController', {}); + + changeInputValueTo(element, 'Al'); + + expect(findMatches(element).eq(0).find('p').text()).toEqual('0 Alaska'); + })); + it('should throw error on invalid expression', function () { var prepareInvalidDir = function () { prepareInputEl('
'); diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 06baa1be81..fa27320fa4 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -383,7 +383,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap link:function (scope, element, attrs) { var tplUrl = $parse(attrs.templateUrl)(scope.$parent) || 'template/typeahead/typeahead-match.html'; $http.get(tplUrl, {cache: $templateCache}).success(function(tplContent){ - element.replaceWith($compile(tplContent.trim())(scope)); + $compile(tplContent.trim())(scope, function(clonedElement){ + element.replaceWith(clonedElement); + }); }); } };