Usage of data attribute VS custom element attribute
-
23-12-2019 - |
Question
I understand that create a custom attribute on a custom element in Polymer allows us to watch for changes to that attribute by specifying a listener. But if I just need to expose a data from my custom element when do I use data attribute and when to use a Polymer's custom attribute?
I also understand that data- takes only strings
Solution
I think you'll pretty much always want to use Polymer's custom attributes unless your attribute has the same name as a built-in attribute (like title
). As you noticed, the change handlers will not work with data-
attributes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow