Last active
December 30, 2015 05:49
-
-
Save IlanFrumer/7784921 to your computer and use it in GitHub Desktop.
Use with angular.js UI-Router directive ui-sref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <a ui-sref="mystate" ui-sref-class="active">link</a> | |
# | |
# whenever the current state is 'mystate' a class of 'active' will be added to the same element. | |
angular.module('ui-sref-class',[]) | |
.directive "uiSrefClass", -> | |
link: (scope, elm , attrs)-> | |
scope.$on '$stateChangeSuccess' , (event, toState)-> | |
if toState.name == attrs.uiSref | |
elm.addClass(attrs.uiSrefClass) | |
else | |
elm.removeClass(attrs.uiSrefClass) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment