Imagine the situation in AngularJS where you want to create a directive that needs to respond to a global event. In this case, let\'s say, the window resize event.
What
The second approach feels more brittle, since Angular offers many ways to refer to the directive in the template (my-directive
, my_directive
, my:directive
, x-my-directive
, data-my-directive
, etc.) so a CSS selector covering them all might get really complex.
This probably isn't a big deal if you only use the directives internally or they consist of a single word. But if other developers (with different coding conventions) might be using your directives, you may want to avoid the second approach.
But I'd be pragmatic. If you're dealing with a handful of instances, go with #1. If you have hundreds of them, I'd go with #2.