Skip to content

Commit 0d9728a

Browse files
committed
feat(tab): make templateUrl configurable
I need the ability to have different markup for some tabs on a page by page basis. Injecting templates with the script tag on each page is getting ugly. This topic was recently brought up again in angular-ui#1611. @sudhakar mentions a similar need for this in angular-ui#105. _Usage_ ```html <tabset> <tab ng-repeat="tab in tabs"> <tabset template-url="custom_tab_template"> <tab ng-repeat="innerTab in tab.tabs"> <span class="inner-tab-content">{{ innerTab.content }}</span> </tab> </tabset> </tab> </tabset> ```
1 parent 3704db9 commit 0d9728a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/tabs/tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ angular.module('ui.bootstrap.tabs', [])
8686
type: '@'
8787
},
8888
controller: 'TabsetController',
89-
templateUrl: 'template/tabs/tabset.html',
89+
templateUrl: function(element, attr) { return attr.templateUrl ? attr.templateUrl : 'template/tabs/tabset.html'; },
9090
link: function(scope, element, attrs) {
9191
scope.vertical = angular.isDefined(attrs.vertical) ? scope.$parent.$eval(attrs.vertical) : false;
9292
scope.justified = angular.isDefined(attrs.justified) ? scope.$parent.$eval(attrs.justified) : false;

src/tabs/test/tabs.spec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,5 +780,55 @@ describe('tabs', function() {
780780
expect(elm.find('.inner-tab-content').eq(1).text().trim()).toEqual(scope.tabs[0].tabs[1].content);
781781
expect(elm.find('.outer-tab-content').eq(0).text().trim()).toEqual(scope.tabs[0].content);
782782
}));
783+
784+
it('template path should be configurable', inject(function($compile, $rootScope, $templateCache) {
785+
$templateCache.put('custom_tab_template',
786+
'<div class="tabbable">' +
787+
'<div class="custom-markup">' +
788+
'<span>Some custom markup</span>' +
789+
'<ul class="nav nav-{{type || \'tabs\'}}" ng-class="{\'nav-stacked\': vertical, \'nav-justified\': justified}" ng-transclude></ul>' +
790+
'</div>' +
791+
'<div class="tab-content">' +
792+
'<div class="tab-pane"' +
793+
'ng-repeat="tab in tabs"' +
794+
'ng-class="{active: tab.active}"' +
795+
'tab-content-transclude="tab">' +
796+
'</div>' +
797+
'</div>' +
798+
'</div>');
799+
800+
var scope = $rootScope.$new();
801+
scope.tabs = [
802+
{
803+
tabs: [
804+
{
805+
content: 'tab1a'
806+
},
807+
{
808+
content: 'tab2a'
809+
}
810+
],
811+
content: 'tab1'
812+
}
813+
];
814+
elm = $compile([
815+
'<div>',
816+
' <tabset>',
817+
' <tab ng-repeat="tab in tabs">',
818+
' <tabset template-url="custom_tab_template">',
819+
' <tab ng-repeat="innerTab in tab.tabs">',
820+
' <span class="inner-tab-content">{{ innerTab.content }}</span>',
821+
' </tab>',
822+
' </tabset>',
823+
' <span class="outer-tab-content">{{ tab.content }}</span>',
824+
' </tab>',
825+
' </tabset>',
826+
'</div>'
827+
].join('\n'))(scope);
828+
scope.$apply();
829+
830+
expect(elm.find('.custom-markup').length).toEqual(1);
831+
expect(elm.find('.custom-markup span').text()).toEqual('Some custom markup');
832+
}));
783833
});
784834
});

0 commit comments

Comments
 (0)