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

feat(accordion): add templateUrl support #4084

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
controller:'AccordionController',
transclude: true,
replace: false,
templateUrl: 'template/accordion/accordion.html'
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion.html';
}
};
})

Expand All @@ -60,7 +62,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
restrict:'EA',
transclude:true, // It transcludes the contents of the directive into the template
replace: true, // The element containing the directive will be replaced with the template
templateUrl:'template/accordion/accordion-group.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion-group.html';
},
scope: {
heading: '@', // Interpolate the heading attribute onto this scope
isOpen: '=?',
Expand Down
7 changes: 7 additions & 0 deletions src/accordion/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ The body of each accordion group is transcluded in to the body of the collapsibl

* `is-open` <i class="glyphicon glyphicon-eye-open"></i> (Defaults: false) :
Whether accordion group is open or closed.
* `template-url` (Defaults: `template/accordion/accordion.html`) :
Add ability to override the template url used

### Accordion Group Settings ###

* `template-url` (Defaults: `template/accordion/accordion-group.html`) :
Add ability to override the template url used
35 changes: 34 additions & 1 deletion src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ describe('accordion', function () {
});
});

describe('accordion', function () {
var scope, $compile, element;

beforeEach(inject(function($rootScope, _$compile_) {
scope = $rootScope;
$compile = _$compile_;
}));

it('should allow custom templates', inject(function ($templateCache, $timeout) {
$templateCache.put('foo/bar.html', '<div>baz</div>');

element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
$timeout(function() {
expect(element.html()).toBe('<div>baz</div>');
});
$timeout.flush();
}));
});

describe('accordion-group', function () {

var scope, $compile;
Expand All @@ -113,7 +132,6 @@ describe('accordion', function () {
return groups.eq(index).find('.panel-collapse').eq(0);
};


beforeEach(inject(function(_$rootScope_, _$compile_) {
scope = _$rootScope_;
$compile = _$compile_;
Expand All @@ -123,6 +141,21 @@ describe('accordion', function () {
element = groups = scope = $compile = undefined;
});

it('should allow custom templates', inject(function ($templateCache, $timeout) {
$templateCache.put('foo/bar.html', '<div>baz</div>');

var tpl =
'<accordion>' +
'<accordion-group heading="title 1" template-url="foo/bar.html"></accordion-group>' +
'</accordion>';

element = $compile(tpl)(scope);
$timeout(function() {
expect(element.find('[template-url]').html()).toBe('baz');
});
$timeout.flush();
}));

describe('with static panels', function () {
beforeEach(function () {
var tpl =
Expand Down