angularjs - How to read an attribute of angular.element without knowing whether it has been prefixed with data- or x-data -


I was wondering if there is a standard way of attaining attribute from an angular element without knowing the name of the attribute, - Prefix with data

I have seen this code inside the instructions:

  el.attr ('x-data-' + attr). | El.attr ('data-' + attr) || El.attr (attr)  

Is this the right approach, or are there some other standards?

In HTML, you can add attributes to elements such as data - *. (Note: always prefix your attribute with data) -

  & lt; Div data-type type = "evaluation" & gt; & Lt; / Div & gt;  

In the JS file you can get the value of the attribute such as

  var val = element.data ('work type');  

(Note: The prefixed part will be skipped here.) Browser: IE9 & amp; Chrome, etc.

If you are not sure about the browser or are not sure what the naming convention will use for your specialty, then you

  el Attr ('x-data-' + attr) || El.attr ('data-' + attr) || El.attr (atri)  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -