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

Commit

Permalink
fix(tabs): make tab contents be correctly connected to parent (#524)
Browse files Browse the repository at this point in the history
* Make tab contents be compiled into outer scope after being appended to
tab-pane elements.
  • Loading branch information
ajoslin committed Jun 28, 2013
1 parent b867538 commit be7ecff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ angular.module('ui.bootstrap.tabs', [])

.controller('TabsetController', ['$scope', '$element',
function TabsetCtrl($scope, $element) {

//Expose the outer scope for tab content compiling, so it can compile
//on outer scope like it should
this.$outerScope = $scope.$parent;

var ctrl = this,
tabs = ctrl.tabs = $scope.tabs = [];

Expand Down Expand Up @@ -280,15 +285,17 @@ function($parse, $http, $templateCache, $compile) {
};
}])

.directive('tabContentTransclude', ['$parse', function($parse) {
.directive('tabContentTransclude', ['$compile', '$parse', function($compile, $parse) {
return {
restrict: 'A',
require: '^tabset',
link: function(scope, elm, attrs, tabsetCtrl) {
var outerScope = tabsetCtrl.$outerScope;
scope.$watch($parse(attrs.tabContentTransclude), function(tab) {
elm.html('');
if (tab) {
elm.append(tab.contentElement);
$compile(tab.contentElement)(outerScope);
}
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/tabs/test/tabsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,18 @@ describe('tabs', function() {
});
});

//https://github.com/angular-ui/bootstrap/issues/524
describe('child compilation', function() {

var elm;
beforeEach(inject(function($compile, $rootScope) {
elm = $compile('<tabset><tab><div></div></tab></tabset></div>')($rootScope.$new());
$rootScope.$apply();
}));

it('should hookup the tab\'s children to the tab with $compile', function() {
var tabChild = $('.tab-pane', elm).children().first();
expect(tabChild.inheritedData('$tabsetController')).toBeTruthy();
});
});
});

0 comments on commit be7ecff

Please sign in to comment.