angularjs - How to read an attribute of angular.element without knowing whether it has been prefixed with data- or x-data -
angularjs - How to read an attribute of angular.element without knowing whether it has been prefixed with data- or x-data -
i wondering, whether there standard way attribute angular element without knowing whether attribute name has been prefixed data- or x-data.
i've seen code within directive:
el.attr('x-data-' + attr) || el.attr('data-' + attr) || el.attr(attr).
is right approach, or there more standard?
in html can add together attribute element data-*.(note:always prefix attribute data-)
<div data-tasktype = "somevalue"> </div>
in js file can fetch value of attribute like
var val = element.data('tasktype');
(note:here prefixed part skipped.) browser:ie9 & above,chrome,etc.
if not sure browser or not sure naming convention going utilize attribute, can go for
el.attr('x-data-' + attr) || el.attr('data-' + attr) || el.attr(attr)
angularjs angularjs-directive
Comments
Post a Comment