Skip to content

Commit c3d83a9

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 <tabset template-url="custom_tab_template"> <tab heading="Stuff"> Some stuff here </tab> </tabset>
1 parent 3704db9 commit c3d83a9

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,5 +780,38 @@ 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+
802+
elm = $compile([
803+
'<div>',
804+
' <tabset template-url="custom_tab_template">',
805+
' <tab heading="Stuff">',
806+
' Some stuff',
807+
' </tab>',
808+
' </tabset>',
809+
'</div>'
810+
].join('\n'))(scope);
811+
scope.$apply();
812+
813+
expect(elm.find('.custom-markup').length).toEqual(1);
814+
expect(elm.find('.custom-markup span').text()).toEqual('Some custom markup');
815+
}));
783816
});
784817
});

0 commit comments

Comments
 (0)