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

feat(tab): add 'template-url' parameter to uib-tab #5443

Closed
wants to merge 2 commits into from
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: 8 additions & 0 deletions src/tabs/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ AngularJS version of the tabs directive.
_(Default: `false`)_ -
Whether tabs fill the container and have a consistent width.

* `template-url`
_(Default: `uib/template/tabs/tabset.html`)_ -
A URL representing the location of a template to use for the main component.

* `type`
_(Defaults: `tabs`)_ -
Navigation type. Possible values are 'tabs' and 'pills'.
Expand Down Expand Up @@ -43,6 +47,10 @@ AngularJS version of the tabs directive.
<small class="badge">$</small> -
An optional expression called when tab is activated.

* `template-url`
_(Default: `uib/template/tabs/tab.html`)_ -
A URL representing the location of a template to use for the tab heading.

### Tabset heading

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.
Expand Down
8 changes: 6 additions & 2 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ angular.module('ui.bootstrap.tabs', [])
},
controller: 'UibTabsetController',
controllerAs: 'tabset',
templateUrl: 'uib/template/tabs/tabset.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'uib/template/tabs/tabset.html';
},
link: function(scope, element, attrs) {
scope.vertical = angular.isDefined(attrs.vertical) ?
scope.$parent.$eval(attrs.vertical) : false;
Expand All @@ -107,7 +109,9 @@ angular.module('ui.bootstrap.tabs', [])
return {
require: '^uibTabset',
replace: true,
templateUrl: 'uib/template/tabs/tab.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'uib/template/tabs/tab.html';
},
transclude: true,
scope: {
heading: '@',
Expand Down
29 changes: 29 additions & 0 deletions src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ describe('tabs', function() {
});
});

describe('custom template', function() {
var $compile, $templateCache;
beforeEach(inject(function($rootScope, _$compile_, _$templateCache_) {
scope = $rootScope;
$compile = _$compile_;
$templateCache = _$templateCache_;
}));

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

elm = $compile('<uib-tabset template-url="foo/bar.html"></uib-tabset>')(scope);
scope.$digest();

expect(elm.html()).toBe('baz');
});
});

describe('uib-tab', function() {
var $compile, $templateCache;

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

expect(tab.text().trim()).toBe('foo');
});

it('should support custom templates', function() {
$templateCache.put('foo/bar.html', '<li>baz</li>');

elm = $compile('<uib-tabset><uib-tab template-url="foo/bar.html"></uib-tab></uib-tabset>')(scope);
scope.$digest();

var tabTitle = titles().eq(0);

expect(tabTitle.html()).toBe('baz');
});
});

describe('ng-repeat', function() {
Expand Down