From what I read (and didn’t get to test!), the only two methods compatible with older versions of IE are the first two: directive as attribute declaration and as class.
<div atributo></div>
<div class="classe"></div>
More to the point, custom tags (<elemento></elemento>
) are not considered valid HTML5, even though they work in the most modern browsers.
Similarly, custom attributes will also not be accepted unless they are started by "date prefix-" (<div data-atributo></div>
). However, it is important to note that if there is interest in validating the code as XHTML5, the minification of attributes (<div data-atributo></div>
) is not permitted, it is mandatory to specify the values of the attributes, however redundant or unnecessary it may seem (<div data-atributo="simQueroAtivarEsteAtributo"></div>
).
So far, logic tells us, then, that the "most correct" would be to use the directive format as a class. However, as discussed in this text by Jeremy Zerr, the Angularjs documentation itself tells us to use
Soon, based on this and the rest of the discussion on his page, he organizes a brief that I found very useful and I will translate (freely) next:
Guidelines for good practice in the Angularjs Directives
- Use your directive as an element name instead of an attribute when you’re in control of the template
- Use your directive as an attribute instead of an element name when you’re adding functionality to an element already
existing
- If you do indeed use a directive as an element, add a prefix to it [and all other directives as elements] to
avoid name conflicts with future versions of HTML5 and with possible
other libraries [Note: this does not make much sense if the names of
directives are in English]
- If validation as HTML5 is a requirement, you will be forced to use all directives as attributes with a "date prefix-"
- If validation as XHTML5 is a requirement, the same validation rules as HTML5 apply, but it is still necessary to add a "=" and a value at the end of the attributes.
- Use isolated scope when possible, but don’t feel defeated if you can’t isolate the scope because of the need to two-way data-bind with an external scope.
I did not signal your answer as correct because I believe John’s answer below is not wrong. But yours brought me some very interesting and specific details, so I gave you the reward.
– rafaels88
Thanks, @rafaels88, good to know that the answer was helpful! But now I need to earn some more points to escape this 666 :D haha Hugs!
– Rui Pimentel