Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's 2 things here:</p> <ol> <li>You don't need 2 directives</li> <li>I had suspected that you would need to use the directive's compile function to get this to work since you're using the directive itself inside its own template, you'll also need to use the injectable <code>$compile</code></li> </ol> <p>I've used the <code>ngIf</code> directive in the template, you don't have to I just wanted to let you know and to warn you that you need to use AngularJS 1.1.5+ in order to use that directive.</p> <p>Here's a JSFiddle I got working: <a href="http://jsfiddle.net/mikeeconroy/7sq3n/6/" rel="nofollow noreferrer">http://jsfiddle.net/mikeeconroy/7sq3n/6/</a></p> <pre><code>.directive("navigation", ['$log','$compile',function ($log,$compile) { return { restrict: 'E', replace: true, scope: { menu: '=' }, template: '&lt;ul&gt;&lt;li ng-repeat="item in menu"&gt;{{item.Name}}&lt;span ng-if="item.Children.length &gt; 0"&gt;&lt;navigation menu="item.Children"&gt;&lt;/navigation&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;', compile: function (el) { var contents = el.contents().remove(); return function(scope,el){ $compile(contents)(scope,function(clone){ el.append(clone); }); }; } }; </code></pre> <p>I cobbled this together with a little help from here: <a href="https://stackoverflow.com/questions/14430655/recursion-in-angular-directives">Recursion in Angular directives</a></p> <p><strong>UPDATE</strong>: <a href="http://jsfiddle.net/mikeeconroy/Z6sG9/2/" rel="nofollow noreferrer">http://jsfiddle.net/mikeeconroy/Z6sG9/2/</a> Solves multiple root element problem</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