Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Last active December 30, 2015 05:49
Show Gist options
  • Save IlanFrumer/7784921 to your computer and use it in GitHub Desktop.
Save IlanFrumer/7784921 to your computer and use it in GitHub Desktop.
Use with angular.js UI-Router directive ui-sref
# <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