Created
October 28, 2013 12:23
-
-
Save thekarel/7195934 to your computer and use it in GitHub Desktop.
AngularJS: add attribute based on watch -- From http://stackoverflow.com/questions/14886174/angular-equivalent-of-ngclass-for-custom-attributes
This file contains hidden or 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('bubble', function() { | |
return function(scope, element, attrs) { | |
// Whatever the data-bubble attr is set to will | |
// be the expression we watch. | |
var expr = attrs.bubble; | |
scope.$watch(expr, function(val) { | |
if (val > 0) { | |
element.attr('data-bubble', val); | |
} else { | |
element.removeAttr('data-bubble'); | |
} | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment