Skip to content

Instantly share code, notes, and snippets.

@devm33
Created September 13, 2015 16:55
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 devm33/fb82461d3fcc8d2aba74 to your computer and use it in GitHub Desktop.
Save devm33/fb82461d3fcc8d2aba74 to your computer and use it in GitHub Desktop.
angular directive to add/remove attributes like ngClass
angular.module('dynAttrs', [])
.directive('dynAttrs', () => {
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.dynAttrs, (dynAttrs) => {
_.each(dynAttrs, (val, attr) => {
if(val) {
element.attr(attr, val);
} else {
element.removeAttr(attr);
}
});
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment