I can not solve this problem.
It is necessary to create tabs with distributed logic for navigation and content (different directives), they communicate with each other using events.
There are no problems with the navigation directive.
All questions about the directive with the display of content. There is a <tabs> directive and there are many <tab> directives within it with a unique attribute key. Each <tab> may contain a different directive / expression / just html. <tab> shown only when the key in its attribute is equal to the variable at the parent <tabs> . It is impossible to implement such a structure.
- How do I pass the value of the variable
item.keyto an attribute directive withng-repeatandng-transclude? (example<tab key="{{item.key}}" repeat="item in items">) - How do I access the
<tab>directive to theselectedTabKeyvariable of the parent<tabs>?
var app = angular.module("app", []); var $ = angular.element; app.run(function($templateCache, $rootScope) { $rootScope.items = [ {key:1,value:'a'}, {key:2,value:'b'}, {key:3,value:'c'} ]; }); app.directive( "tabs", function() { return { restrict: "AE", scope: true, transclude: true, replace: true, template: "<div ng-transclude></div>", link: function(scope, elem, attr, ctrl) { scope.selectedTabKey = 2; // TODO: changing the selectedTabKey value // want to show/hide the related tab } }; }); app.directive( "tab", function($compile) { return { restrict: "AE", transclude: true, replace: true, template: "<div><span transclude></span></div>", link: function( scope, elem, attr, ctrl, transclude ) { var transc = $(elem[0].querySelector( "[transclude]" )); transclude( scope, function( childs ) { transc.append( childs ); }); transc.attr("ng-repeat", attr.repeat); $compile(transc)(scope); // todo: access parent's var `selectedTabKey` // and make visible the related tab } }; }); <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script> <div ng-app="app"> <tabs> <!-- how to pass the attr {{item.key}} below? --> <tab key="{{item.key}}" repeat="item in items"> <!-- here some directive/expression/plain html --> {{item.value}} </tab> </tabs> </div>
tab. But you need to look at therequired- Grundy property