Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit f777c32

Browse files
committed
feat(accordion): add templateUrl support
- Add ability to override the template of the `accordion` and `accordion-group` directives on an instance by instance basis Closes #4084
1 parent b18dc8f commit f777c32

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/accordion/accordion.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
4949
controller:'AccordionController',
5050
transclude: true,
5151
replace: false,
52-
templateUrl: 'template/accordion/accordion.html'
52+
templateUrl: function(element, attrs) {
53+
return attrs.templateUrl || 'template/accordion/accordion.html';
54+
}
5355
};
5456
})
5557

@@ -60,7 +62,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
6062
restrict:'EA',
6163
transclude:true, // It transcludes the contents of the directive into the template
6264
replace: true, // The element containing the directive will be replaced with the template
63-
templateUrl:'template/accordion/accordion-group.html',
65+
templateUrl: function(element, attrs) {
66+
return attrs.templateUrl || 'template/accordion/accordion-group.html';
67+
},
6468
scope: {
6569
heading: '@', // Interpolate the heading attribute onto this scope
6670
isOpen: '=?',

src/accordion/docs/readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ The body of each accordion group is transcluded in to the body of the collapsibl
88

99
* `is-open` <i class="glyphicon glyphicon-eye-open"></i> (Defaults: false) :
1010
Whether accordion group is open or closed.
11+
* `template-url` (Defaults: `template/accordion/accordion.html`) :
12+
Add ability to override the template url used
13+
14+
### Accordion Group Settings ###
15+
16+
* `template-url` (Defaults: `template/accordion/accordion-group.html`) :
17+
Add ability to override the template url used

src/accordion/test/accordion.spec.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ describe('accordion', function () {
102102
});
103103
});
104104

105+
describe('accordion', function () {
106+
var scope, $compile, element;
107+
108+
beforeEach(inject(function($rootScope, _$compile_) {
109+
scope = $rootScope;
110+
$compile = _$compile_;
111+
}));
112+
113+
it('should allow custom templates', inject(function ($templateCache) {
114+
$templateCache.put('foo/bar.html', '<div>baz</div>');
115+
116+
element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
117+
scope.$digest();
118+
expect(element.html()).toBe('<div>baz</div>');
119+
}));
120+
});
121+
105122
describe('accordion-group', function () {
106123

107124
var scope, $compile;
@@ -113,7 +130,6 @@ describe('accordion', function () {
113130
return groups.eq(index).find('.panel-collapse').eq(0);
114131
};
115132

116-
117133
beforeEach(inject(function(_$rootScope_, _$compile_) {
118134
scope = _$rootScope_;
119135
$compile = _$compile_;
@@ -123,6 +139,19 @@ describe('accordion', function () {
123139
element = groups = scope = $compile = undefined;
124140
});
125141

142+
it('should allow custom templates', inject(function ($templateCache) {
143+
$templateCache.put('foo/bar.html', '<div>baz</div>');
144+
145+
var tpl =
146+
'<accordion>' +
147+
'<accordion-group heading="title 1" template-url="foo/bar.html"></accordion-group>' +
148+
'</accordion>';
149+
150+
element = $compile(tpl)(scope);
151+
scope.$digest();
152+
expect(element.find('[template-url]').html()).toBe('baz');
153+
}));
154+
126155
describe('with static panels', function () {
127156
beforeEach(function () {
128157
var tpl =

0 commit comments

Comments
 (0)