<!DOCTYPE html>
<
html
>
<
head
>
<
title
>How to set active tab style with AngularJS?</
title
>
</
head
>
<
body
>
<
div
ng-app
=
"link"
>
<
a
href
=
"#Geeks For Geeks"
active-link
=
"active"
>
Geeks For Geeks
</
a
>
<
a
href
=
"#HTML"
active-link
=
"active"
>HTML</
a
>
<
a
href
=
"#JAVASCRIPT"
active-link
=
"active"
>JAVASCRIPT</
a
>
</
div
>
<
script
>
angular.module('link', []).directive('Link',
['$location', function(location) {
return {
link: function(scope, element, attrs) {
var active = attrs.activeLink;
var path = attrs.href;
path = path.substring(1);
scope.location = location;
scope.$watch('location.path()', function(newPath) {
if(path === newPath) {
element.addClass(active);
} else {
element.removeClass(active);
}
});
}
};
}]);
</
script
>
</
body
>
</
html
>