Skip to content

Instantly share code, notes, and snippets.

@yaplex
Created June 20, 2017 19:42
Show Gist options
  • Select an option

  • Save yaplex/32f34f7b87154c7abd099b8e6bb24b40 to your computer and use it in GitHub Desktop.

Select an option

Save yaplex/32f34f7b87154c7abd099b8e6bb24b40 to your computer and use it in GitHub Desktop.
focusApp.directive('activeLink', function($location) {
var link = function(scope, element, attrs) {
scope.$watch(function() { return $location.path(); },
function(path) {
var url = element.find('a').attr('href');
if (url) {
url = url.substring(1);
}
if (path == url) {
element.addClass("active");
} else {
element.removeClass('active');
}
});
};
return {
restrict: 'A',
link: link
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment