How to add dynamically extended element with Polymer?

xliiv

I've got button:

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-input/core-input.html">

<polymer-element name="count-button" extends="button" on-click="increment">
  <template>
    <content>Increment: </content>
  </template>

  <script>
    Polymer({
      counter: 0,
      increment: function(e, detail, sender) {
          this.counter++;
          alert(this.counter);
      }
    })
  </script>
</polymer-element>

I successfully use it in html by:

<button is="count-button"></button>

How to add such button in js? My incorrect version is (ready function):

<link rel="import" href="../bower_components/polymer/polymer.html">

<polymer-element name='my-input'>
    <template>
        my input
        <style>
        </style>
    </template>
    <script>
        Polymer('my-input', {
            publish: {
            },
            ready: function() {
                var node = document.createElement("button");
                node.setAttribute('is', 'count-button');
                this.shadowRoot.appendChild(node);
            }
        });
    </script>
</polymer-element>
xliiv

I've found the solution by my self and it's as easy as these 2 lines:

var node = document.createElement("button", 'count-button');
this.shadowRoot.appendChild(node);

So the complete answer is here:

<link rel="import" href="../bower_components/polymer/polymer.html">

<polymer-element name='my-input'>
    <template>
        my input
        <style>
        </style>
    </template>
    <script>
        Polymer('my-input', {
            publish: {
            },
            ready: function() {
                # only these 2 lines
                var node = document.createElement("button", 'count-button');
                this.shadowRoot.appendChild(node);
            }
        });
    </script>
</polymer-element>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to dynamically create a polymer element

From Dev

How to style polymer element dynamically

From Dev

How to style polymer element dynamically

From Dev

How to programmatically add extended LIElement in Polymer Dart?

From Dev

how to dynamically append an element to dom-if in Polymer?

From Dev

How to create dynamically polymer element\simple tag

From Dev

Dynamically create polymer element

From Dev

Styling Polymer Element Dynamically

From Dev

How to add function attribute to polymer element

From Dev

Add a class to polymer element

From Dev

Polymer : How to procedurally add nodes to a polymer-element's Light Dom, from inside the element?

From Dev

Dynamically inserted Element within Polymer Element not Visible

From Dev

Trying to populate a Polymer Element's <content></content> through an extended element

From Dev

How do I add JavaScript DOM API to my Polymer element?

From Dev

how do you programatically add markers to the polymer google map element

From Dev

how to add style of host element in Google polymer framework

From Dev

how do you programatically add markers to the polymer google map element

From Dev

How to add an event listener to a custom element property in Polymer?

From Dev

How to add CSS class dynamically to html element

From Dev

How to dynamically add a directive to an input element in AngularJS

From Dev

How to add canvas to div element dynamically?

From Dev

How to dynamically add HTML element/content - Angular

From Dev

Polymer: How to add event listeners to custom polymer element under conditional template

From Dev

Dynamically setting polymer custom element event handler

From Dev

Data binding in a dynamically inserted polymer element

From Dev

Dynamically inject shared styles in polymer element (polymer 1.2.3)

From Dev

Polymer: is possible to add <content> inside a select (native or extended) tag?

From Dev

Polymer 1.0 dynamically add options to menu

From Dev

Dynamically add element to layout

Related Related

  1. 1

    How to dynamically create a polymer element

  2. 2

    How to style polymer element dynamically

  3. 3

    How to style polymer element dynamically

  4. 4

    How to programmatically add extended LIElement in Polymer Dart?

  5. 5

    how to dynamically append an element to dom-if in Polymer?

  6. 6

    How to create dynamically polymer element\simple tag

  7. 7

    Dynamically create polymer element

  8. 8

    Styling Polymer Element Dynamically

  9. 9

    How to add function attribute to polymer element

  10. 10

    Add a class to polymer element

  11. 11

    Polymer : How to procedurally add nodes to a polymer-element's Light Dom, from inside the element?

  12. 12

    Dynamically inserted Element within Polymer Element not Visible

  13. 13

    Trying to populate a Polymer Element's <content></content> through an extended element

  14. 14

    How do I add JavaScript DOM API to my Polymer element?

  15. 15

    how do you programatically add markers to the polymer google map element

  16. 16

    how to add style of host element in Google polymer framework

  17. 17

    how do you programatically add markers to the polymer google map element

  18. 18

    How to add an event listener to a custom element property in Polymer?

  19. 19

    How to add CSS class dynamically to html element

  20. 20

    How to dynamically add a directive to an input element in AngularJS

  21. 21

    How to add canvas to div element dynamically?

  22. 22

    How to dynamically add HTML element/content - Angular

  23. 23

    Polymer: How to add event listeners to custom polymer element under conditional template

  24. 24

    Dynamically setting polymer custom element event handler

  25. 25

    Data binding in a dynamically inserted polymer element

  26. 26

    Dynamically inject shared styles in polymer element (polymer 1.2.3)

  27. 27

    Polymer: is possible to add <content> inside a select (native or extended) tag?

  28. 28

    Polymer 1.0 dynamically add options to menu

  29. 29

    Dynamically add element to layout

HotTag

Archive