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

Commit 54c51c4

Browse files
Graham Roundswesleycho
Graham Rounds
authored andcommitted
feat(tab): add template-url support
- Adds support for `template-url` for tabset and tab directives Closes #5405 Closes #5443
1 parent c5397a8 commit 54c51c4

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Diff for: src/tabs/docs/readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ AngularJS version of the tabs directive.
1212
_(Default: `false`)_ -
1313
Whether tabs fill the container and have a consistent width.
1414

15+
* `template-url`
16+
_(Default: `uib/template/tabs/tabset.html`)_ -
17+
A URL representing the location of a template to use for the main component.
18+
1519
* `type`
1620
_(Defaults: `tabs`)_ -
1721
Navigation type. Possible values are 'tabs' and 'pills'.
@@ -43,6 +47,10 @@ AngularJS version of the tabs directive.
4347
<small class="badge">$</small> -
4448
An optional expression called when tab is activated.
4549

50+
* `template-url`
51+
_(Default: `uib/template/tabs/tab.html`)_ -
52+
A URL representing the location of a template to use for the tab heading.
53+
4654
### Tabset heading
4755

4856
Instead of the `heading` attribute on the `uib-tabset`, you can use an `uib-tab-heading` element inside a tabset that will be used as the tabset's header. There you can use HTML as well.

Diff for: src/tabs/tabs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ angular.module('ui.bootstrap.tabs', [])
9393
},
9494
controller: 'UibTabsetController',
9595
controllerAs: 'tabset',
96-
templateUrl: 'uib/template/tabs/tabset.html',
96+
templateUrl: function(element, attrs) {
97+
return attrs.templateUrl || 'uib/template/tabs/tabset.html';
98+
},
9799
link: function(scope, element, attrs) {
98100
scope.vertical = angular.isDefined(attrs.vertical) ?
99101
scope.$parent.$eval(attrs.vertical) : false;
@@ -107,7 +109,9 @@ angular.module('ui.bootstrap.tabs', [])
107109
return {
108110
require: '^uibTabset',
109111
replace: true,
110-
templateUrl: 'uib/template/tabs/tab.html',
112+
templateUrl: function(element, attrs) {
113+
return attrs.templateUrl || 'uib/template/tabs/tab.html';
114+
},
111115
transclude: true,
112116
scope: {
113117
heading: '@',

Diff for: src/tabs/test/tabs.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ describe('tabs', function() {
191191
});
192192
});
193193

194+
describe('custom template', function() {
195+
var $compile, $templateCache;
196+
beforeEach(inject(function($rootScope, _$compile_, _$templateCache_) {
197+
scope = $rootScope;
198+
$compile = _$compile_;
199+
$templateCache = _$templateCache_;
200+
}));
201+
202+
it('should support custom templates', function() {
203+
$templateCache.put('foo/bar.html', '<div>baz</div>');
204+
205+
elm = $compile('<uib-tabset template-url="foo/bar.html"></uib-tabset>')(scope);
206+
scope.$digest();
207+
208+
expect(elm.html()).toBe('baz');
209+
});
210+
});
211+
194212
describe('uib-tab', function() {
195213
var $compile, $templateCache;
196214

@@ -216,6 +234,17 @@ describe('tabs', function() {
216234

217235
expect(tab.text().trim()).toBe('foo');
218236
});
237+
238+
it('should support custom templates', function() {
239+
$templateCache.put('foo/bar.html', '<li>baz</li>');
240+
241+
elm = $compile('<uib-tabset><uib-tab template-url="foo/bar.html"></uib-tab></uib-tabset>')(scope);
242+
scope.$digest();
243+
244+
var tabTitle = titles().eq(0);
245+
246+
expect(tabTitle.html()).toBe('baz');
247+
});
219248
});
220249

221250
describe('ng-repeat', function() {

0 commit comments

Comments
 (0)