Retrieving a List of Published Polymer Properties

Is there a way to get a list of all published properties defined in the polymer component? (for example, get the available properties of the public component API)

<polymer-element name="sample-component"
                 attributes="foo1 foo2" bar="10">
   /* ... */
</polymer-element>

<sample-component foo1="5"></sample-component>


document.querySellector('sample-component').attributes;
// returns bar and foo1 (which have a value assigned to them)
// but I want to get foo1 and foo2
+2
source share
2 answers

Best used element.publishto get a list of published properties for an element. (In polymers, 1.0 element.propertiesdoes the same).

element.getAttribute('attributes)will not include publishing properties that are set in the block publish.

+3
source

You can access the definition of an element (i.e. itself polymer-element) using a property element. So,

document.querySelector('sample-component')
  .element.getAttribute('attributes')

'foo1 foo2' (btw , this.element.)

, , Polymer , , , , , polymer-ready:

<script>
  addEventListener('polymer-ready', function() {
    console.log(document.querySelector('sample-component')
      .element.getAttribute('attributes'));
  });
</script>

Update:

(.. , attributes publish: {}),

   Object.keys(document.querySelector('sample-component').publish)

['foo1', 'foo2'].

+1

All Articles