Skip to content

Instantly share code, notes, and snippets.

@ashmind
Created May 9, 2014 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashmind/d58c65d198c193981969 to your computer and use it in GitHub Desktop.
Save ashmind/d58c65d198c193981969 to your computer and use it in GitHub Desktop.
angular.module('...').directive('ancestorClass', function() {
'use strict';
function link(scope, element, attrs) {
var targets = element.parents().filter(attrs.selector);
scope.$watch(attrs.class, function(value) {
for (var key in value) {
targets.toggleClass(key, value[key]);
}
}, true);
};
return {
link: link,
restrict: 'E'
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment