From f777c320ccd45531490b2bbb58fd31e9c6472fdc Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sun, 2 Aug 2015 22:38:54 -0700 Subject: [PATCH] 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 --- src/accordion/accordion.js | 8 +++++-- src/accordion/docs/readme.md | 7 +++++++ src/accordion/test/accordion.spec.js | 31 +++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/accordion/accordion.js b/src/accordion/accordion.js index 348bd79f9c..b705701c97 100644 --- a/src/accordion/accordion.js +++ b/src/accordion/accordion.js @@ -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'; + } }; }) @@ -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: '=?', diff --git a/src/accordion/docs/readme.md b/src/accordion/docs/readme.md index 1a67460cbe..5af801726c 100644 --- a/src/accordion/docs/readme.md +++ b/src/accordion/docs/readme.md @@ -8,3 +8,10 @@ The body of each accordion group is transcluded in to the body of the collapsibl * `is-open` (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 diff --git a/src/accordion/test/accordion.spec.js b/src/accordion/test/accordion.spec.js index 0a5c4134c6..0436655da8 100644 --- a/src/accordion/test/accordion.spec.js +++ b/src/accordion/test/accordion.spec.js @@ -102,6 +102,23 @@ 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) { + $templateCache.put('foo/bar.html', '
baz
'); + + element = $compile('')(scope); + scope.$digest(); + expect(element.html()).toBe('
baz
'); + })); + }); + describe('accordion-group', function () { var scope, $compile; @@ -113,7 +130,6 @@ describe('accordion', function () { return groups.eq(index).find('.panel-collapse').eq(0); }; - beforeEach(inject(function(_$rootScope_, _$compile_) { scope = _$rootScope_; $compile = _$compile_; @@ -123,6 +139,19 @@ describe('accordion', function () { element = groups = scope = $compile = undefined; }); + it('should allow custom templates', inject(function ($templateCache) { + $templateCache.put('foo/bar.html', '
baz
'); + + var tpl = + '' + + '' + + ''; + + element = $compile(tpl)(scope); + scope.$digest(); + expect(element.find('[template-url]').html()).toBe('baz'); + })); + describe('with static panels', function () { beforeEach(function () { var tpl =