diff --git a/src/typeahead/docs/demo.html b/src/typeahead/docs/demo.html
index b0d4b19..3121863 100644
--- a/src/typeahead/docs/demo.html
+++ b/src/typeahead/docs/demo.html
@@ -4,6 +4,16 @@
+
+
+
diff --git a/src/typeahead/docs/readme.md b/src/typeahead/docs/readme.md
index b4c62d6..7301b4c 100644
--- a/src/typeahead/docs/readme.md
+++ b/src/typeahead/docs/readme.md
@@ -45,6 +45,10 @@ The typeahead directives provide several attributes:
:
Set custom item template
+* `typeahead-popup-template-url`
+ :
+ Set custom results popup template
+
* `typeahead-wait-ms`
_(Defaults: 0)_ :
Minimal wait time after last character typed before typeahead kicks-in
diff --git a/src/typeahead/test/typeahead-popup.spec.js b/src/typeahead/test/typeahead-popup.spec.js
index 2f17851..ba90bf8 100644
--- a/src/typeahead/test/typeahead-popup.spec.js
+++ b/src/typeahead/test/typeahead-popup.spec.js
@@ -1,14 +1,15 @@
describe('typeaheadPopup - result rendering', function () {
- var scope, $rootScope, $compile;
+ var scope, $rootScope, $compile, $templateCache;
beforeEach(module('mm.foundation.typeahead'));
beforeEach(module('template/typeahead/typeahead-popup.html'));
beforeEach(module('template/typeahead/typeahead-match.html'));
- beforeEach(inject(function (_$rootScope_, _$compile_) {
+ beforeEach(inject(function (_$rootScope_, _$compile_, _$templateCache_) {
$rootScope = _$rootScope_;
scope = $rootScope.$new();
$compile = _$compile_;
+ $templateCache = _$templateCache_;
}));
it('should render initial results', function () {
@@ -58,4 +59,17 @@ describe('typeaheadPopup - result rendering', function () {
liElems.eq(2).find('a').trigger('click');
expect($rootScope.select).toHaveBeenCalledWith(2);
});
+
+ it('should allow a custom template', function () {
+ $templateCache.put('/custom', 'Some content
');
+ spyOn($templateCache, 'get').andCallThrough();
+
+ var el = $compile("
")(scope);
+ $rootScope.$digest();
+
+ expect($templateCache.get).toHaveBeenCalledWith('/custom');
+ var divElem = el.find('div#custom-template');
+ expect(divElem.html()).toContain('Some content');
+ });
+
});
diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js
index 6316225..a77dad3 100644
--- a/src/typeahead/typeahead.js
+++ b/src/typeahead/typeahead.js
@@ -83,6 +83,10 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
popUpEl.attr('template-url', attrs.typeaheadTemplateUrl);
}
+ if (angular.isDefined(attrs.typeaheadPopupTemplateUrl)) {
+ popUpEl.attr('popup-template-url', attrs.typeaheadPopupTemplateUrl);
+ }
+
//create a child scope for the typeahead directive so we are not polluting original scope
//with typeahead-specific data (matches, query etc.)
var scope = originalScope.$new();
@@ -298,7 +302,9 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
select:'&'
},
replace:true,
- templateUrl:'template/typeahead/typeahead-popup.html',
+ templateUrl: function(element, attrs) {
+ return attrs.popupTemplateUrl || 'template/typeahead/typeahead-popup.html';
+ },
link:function (scope, element, attrs) {
scope.templateUrl = attrs.templateUrl;