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

Commit be7ecff

Browse files
committed
fix(tabs): make tab contents be correctly connected to parent (#524)
* Make tab contents be compiled into outer scope after being appended to tab-pane elements.
1 parent b867538 commit be7ecff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/tabs/tabs.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ angular.module('ui.bootstrap.tabs', [])
1717

1818
.controller('TabsetController', ['$scope', '$element',
1919
function TabsetCtrl($scope, $element) {
20+
21+
//Expose the outer scope for tab content compiling, so it can compile
22+
//on outer scope like it should
23+
this.$outerScope = $scope.$parent;
24+
2025
var ctrl = this,
2126
tabs = ctrl.tabs = $scope.tabs = [];
2227

@@ -280,15 +285,17 @@ function($parse, $http, $templateCache, $compile) {
280285
};
281286
}])
282287

283-
.directive('tabContentTransclude', ['$parse', function($parse) {
288+
.directive('tabContentTransclude', ['$compile', '$parse', function($compile, $parse) {
284289
return {
285290
restrict: 'A',
286291
require: '^tabset',
287292
link: function(scope, elm, attrs, tabsetCtrl) {
293+
var outerScope = tabsetCtrl.$outerScope;
288294
scope.$watch($parse(attrs.tabContentTransclude), function(tab) {
289295
elm.html('');
290296
if (tab) {
291297
elm.append(tab.contentElement);
298+
$compile(tab.contentElement)(outerScope);
292299
}
293300
});
294301
}

src/tabs/test/tabsSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,18 @@ describe('tabs', function() {
475475
});
476476
});
477477

478+
//https://github.com/angular-ui/bootstrap/issues/524
479+
describe('child compilation', function() {
480+
481+
var elm;
482+
beforeEach(inject(function($compile, $rootScope) {
483+
elm = $compile('<tabset><tab><div></div></tab></tabset></div>')($rootScope.$new());
484+
$rootScope.$apply();
485+
}));
486+
487+
it('should hookup the tab\'s children to the tab with $compile', function() {
488+
var tabChild = $('.tab-pane', elm).children().first();
489+
expect(tabChild.inheritedData('$tabsetController')).toBeTruthy();
490+
});
491+
});
478492
});

0 commit comments

Comments
 (0)