Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(EDIT) Giving some thought after the conversation in the comments, I came up with a better solution. Here is the modified plunk:</p> <p><a href="http://plnkr.co/edit/djNk8PPzXvngZOvAirMu?p=preview" rel="nofollow">http://plnkr.co/edit/djNk8PPzXvngZOvAirMu?p=preview</a></p> <p>The key points of this implementation are:</p> <ul> <li><p>Every directive transcludes its content. This means that, even the innermost directives have access to the outer scope, as is expected. So no more <code>$parent.$parent...</code> awfulness.</p></li> <li><p>Every directive has an isolated scope. As per the docs the isolated scope is side-by-side with the transcluded one; therefore all the private state of the directives (in this case the active tab, the index of each <code>tabItem</code> and some directive-specific functions) is kept in the isolated scope.</p></li> <li><p>The directives communicate through the controllers. This pattern requires a top level "coordinator" (here the <code>tab</code> for all descendant directives and the <code>tabItem</code> for the <code>tabItemHeader</code> and <code>tabItemBody</code>).</p></li> </ul> <p>By the way, if you want tabs, I would suggest Angular UI.</p> <hr> <p>This was a crazy puzzler.</p> <p>The reason for your problem is that the <code>tabItem</code> directive had no reason to transclude its contents; this transclusion created a sibling scope that totally messed up your logic!</p> <p>Thus the answer is simple: remove these lines from the <code>tabItem</code> directive:</p> <pre><code>// REMOVE THEM!!! transclude: true, template: '&lt;div ng-transclude&gt;&lt;/div&gt;', </code></pre> <p>A plunkr with these lines commented out that prints scope ids: <a href="http://plnkr.co/edit/bBfEej145s1YjcE9n3Lj?p=preview" rel="nofollow">http://plnkr.co/edit/bBfEej145s1YjcE9n3Lj?p=preview</a> (this helps with debugging; see what happens when you include these lines, the templates and the linker function see different scopes!)</p> <p>And your plunkr forked, with those lines commented out: <a href="http://plnkr.co/edit/tgZqjZk0bRCyZiHKM0Sy?p=preview" rel="nofollow">http://plnkr.co/edit/tgZqjZk0bRCyZiHKM0Sy?p=preview</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload