Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found XMLilley's anwser the best and most adaptable and non-intrusive.</p> <p>However I had a small glitch.</p> <p>For use with bootstrap nav, here is how I modified it:</p> <pre><code>app.directive('activeTab', function ($location) { return { link: function postLink(scope, element, attrs) { scope.$on("$routeChangeSuccess", function (event, current, previous) { /* designed for full re-usability at any path, any level, by using data from attrs declare like this: &lt;li class="nav_tab"&gt;&lt;a href="#/home" active-tab="1"&gt;HOME&lt;/a&gt;&lt;/li&gt; */ if(attrs.href!=undefined){// this directive is called twice for some reason // this var grabs the tab-level off the attribute, or defaults to 1 var pathLevel = attrs.activeTab || 1, // this var finds what the path is at the level specified pathToCheck = $location.path().split('/')[pathLevel], // this var finds grabs the same level of the href attribute tabLink = attrs.href.split('/')[pathLevel]; // now compare the two: if (pathToCheck === tabLink) { element.parent().addClass("active");//parent to get the &lt;li&gt; } else { element.parent().removeClass("active"); } } }); } }; }); </code></pre> <p>I added "if(attrs.href!=undefined)" because this function is apprently called twice, the second time producing an error.</p> <p>As for the html:</p> <pre><code>&lt;ul class="nav nav-tabs"&gt; &lt;li class="active" active-tab="1"&gt;&lt;a href="#/accueil" active-tab="1"&gt;Accueil&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a active-tab="1" href="#/news"&gt;News&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a active-tab="1" href="#/photos" &gt;Photos&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a active-tab="1" href="#/contact"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre>
 

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