diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js
index ac4f346ea5..dbfc13afb2 100644
--- a/src/typeahead/test/typeahead.spec.js
+++ b/src/typeahead/test/typeahead.spec.js
@@ -1243,3 +1243,49 @@ describe('typeahead tests', function() {
});
});
});
+
+describe('typeahead tests', function() {
+ it('should allow directives in template to require parent controller', function() {
+ module('ui.bootstrap.typeahead');
+ module('ngSanitize');
+ module('template/typeahead/typeahead-popup.html');
+ module(function($compileProvider) {
+ $compileProvider
+ .directive('uibCustomParent', function() {
+ return {
+ controller: function() {
+ this.text = 'foo';
+ }
+ };
+ })
+ .directive('uibCustomDirective', function() {
+ return {
+ require: '^uibCustomParent',
+ link: function(scope, element, attrs, ctrl) {
+ scope.text = ctrl.text;
+ }
+ };
+ });
+ });
+
+ inject(function($compile, $rootScope, $sniffer, $templateCache) {
+ var element;
+ var $scope = $rootScope.$new();
+ $templateCache.put('template/typeahead/typeahead-match.html', '
{{text}}
');
+ $scope.states = [
+ {code: 'AL', name: 'Alaska'},
+ {code: 'CL', name: 'California'}
+ ];
+
+ element = $compile('')($scope);
+ $rootScope.$digest();
+
+ var inputEl = element.find('input');
+ inputEl.val('Al');
+ inputEl.trigger($sniffer.hasEvent('input') ? 'input' : 'change');
+ $scope.$digest();
+
+ expect(element.find('ul.dropdown-menu li').eq(0).find('[uib-custom-directive]').text()).toEqual('foo');
+ });
+ });
+});
diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js
index 67844c10d3..6ac2a6775f 100644
--- a/src/typeahead/typeahead.js
+++ b/src/typeahead/typeahead.js
@@ -573,9 +573,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
link: function(scope, element, attrs) {
var tplUrl = $parse(attrs.templateUrl)(scope.$parent) || 'template/typeahead/typeahead-match.html';
$templateRequest(tplUrl).then(function(tplContent) {
- $compile(tplContent.trim())(scope, function(clonedElement) {
- element.replaceWith(clonedElement);
- });
+ var tplEl = angular.element(tplContent.trim());
+ element.replaceWith(tplEl);
+ $compile(tplEl)(scope);
});
}
};