I'm trying to extend the angular-ui tabset functionality and I'm running into issues with wrapping it.
This plunker is the tabset directive un-wrapped:
http://plnkr.co/edit/AhG3WVNxCal5fZOUbSu6?p=preview
This plunker contains my first attempt at wrapping the tabset directive:
http://plnkr.co/edit/naKXbeVOS8nizwDPUrkT?p=preview
The initial wrapping approach is straight-forward wrapping. But... I introduce extra divs in the replacement template to avoid the "Multiple directives asking for isolated scope" and "Multiple directives asking for transclusion" angular errors and to make sure transclusion happens.
Key code snippets:
.directive('urlTabset', function() {
return {
restrict: 'E',
transclude: true,
replace: true,
scope: {
tabManager: '='
},
controller: [ "$scope", function($scope) {
var tabManager = $scope.tabManager;
}],
template:
'<div>' +
'<tabset>' +
'<div ng-transclude>' +
'</div>' +
'</tabset>' +
'</div>'
};
})
.directive('urlTab', function() {
return {
require: '^urlTabset',
restrict: 'E',
transclude: true,
replace: true,
scope: { tabName: '@' },
link: function(scope, element, attrs, urlTabsetCtrl) {
},
template:
'<div>' +
'<tab>' +
'<div ng-transclude>' +
'</div>' +
'</tab>' +
'</div>'
};
});
However, I think the extra divs in the template are causing issues. Here is the unwrapped tabset with extra divs in the places my template would add them.
http://plnkr.co/edit/kjDs7xJcZqltCAqUSAmX?p=preview
So the logical thing is to eliminate the divs... but this is where I need the help. Does anyone know of a clean way to do this without hitting the "Multiple directives asking for isolated scope" and "Multiple directives asking for transclusion" angular errors. Here is one failed attempt.
http://plnkr.co/edit/0C6lFNhfdTVcF7ahuN3G?p=preview
Error: Multiple directives [urlTab, tab] asking for transclusion on: <tab class="ng-isolate-scope ng-scope">
BTW, in case you're wondering what I'm trying to do, my end goal is to use the tabManager attribute passed to urlTabset to auto-populate fields in the tab directive (wrapped by urlTab). To be more concrete this is what I'm aiming for:
.directive('urlTab', function() {
return {
require: '^urlTabset',
restrict: 'E',
transclude: true,
replace: true,
scope: { tabName: '@' },
link: function(scope, element, attrs, urlTabsetCtrl) {
scope.tabs = urlTabsetCtrl.tabs;
scope.tabSelected = urlTabsetCtrl.tabSelected;
},
template:
'<tab active="tabs[tabName].active" disabled="tabs[tabName].disabled" select="tabSelected(tabName)" ng-transclude>' +
'</tab>'
};
});
The template above obviously does not work, but it gives you the gist of what I'm trying to do.
And I'm okay with a solution that requires the wrapping directive not have an isolated scope. I can get around this by storing state in the controller context.