Last active
August 29, 2015 14:02
-
-
Save tkh44/808cc4e16ef61bb24374 to your computer and use it in GitHub Desktop.
Simple directive to toggle class on click. Can either be applied to element defined on or a child of $element.
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
app.directive('toggleClass', function () { | |
return { | |
restrict: 'A', | |
scope: { | |
target: '@', | |
toggleClass: '@' | |
}, | |
link: function ($scope, $element, $attr) { | |
$scope.$targetElement = angular.isDefined($scope.target)? $element.find($scope.target): $element; | |
$element.bind('click', function (e) { | |
$scope.$targetElement.toggleClass($scope.toggleClass); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment