As I read (and did not test !), the only two methods compatible with older versions of IE are the first two: directive as an attribute declaration and as a class.
<div atributo></div>
<div class="classe"></div>
Furthermore, custom tags ( <elemento></elemento>
) are not considered valid HTML5, however much they work in more modern browsers.
Likewise, custom attributes will also not be accepted unless they are initialized by the "data-" 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 allowed, and it is mandatory to explicitly attribute values, however redundant or unnecessary it may appear ( <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 Jeremy Zerr's in this text , AngularJS's own documentation tells us to use
So, based on this and the rest of the discussion of his page, he organizes a short summary that I found very useful and will translate ( freely)
Guidelines for good practice in the AngularJS Directives
Use your directive as an element name instead of an attribute when you are in control of the template
Use your directive as an attribute rather than an element name when you are adding functionality to an element already
existing
If you actually 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 Portuguese]
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, however it is still necessary to add a "=" and a value to the end of the attributes.
Use isolated scope when possible, but do not feel defeated if you can not isolate the scope because of the need for a two-way data-bind with an external scope.