Current menu item class with angular.js? Why not working?

As the topic say I want to highlight current menu item with a class “active”, using angular.js.

My html looks like this:

			<li><a is-active-nav href="#feed">Feed</a></li>
			<li><a is-active-nav href="#test">Test</a></li>
			<li><a is-active-nav href="#feedback">Feedback</a></li>

And my JS like:

var app = angular.module('app', ['ngRoute', 'ngAnimate']);

app.directive('isActiveNav', [ '$location', function($location) {
return {
 restrict: 'A',
 link: function(scope, element) {
   scope.location = $location;
   scope.$watch('location.path()', function(currentPath) {
     if('/#' + currentPath === element[0].attributes['href'].nodeValue) {
     } else {

Looked at this: (

But I can’t get it to work, the link doesn’t get the class. Can anyone see why?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.