1
votes

I am building a polymer element hosting frame, where the user can configure what item they want to be hosted inside the outerframe with header. For instance if the content is set to 'paper-button' the host will display the button with toolbar. Where do I add the appendChild code, it doesn't work on ready or attached event?

<dom-module id="element-host">
    <template>
        <paper-header-panel>
            <paper-toolbar>Header</paper-toolbar>
            <content id="content"></content>
        </paper-header-panel>
    </template>
    <script>
        Polymer({
            is: 'element-host',
            properties: {
                content : {
                    type: string
                }
            },
            attached: function(renderer) {
                var customElement = document.createElement(this.content);
                this.$.content.appendChild(customElement);
            }
        });
    </script>
</dom-module>
2
I think you need to do this on phase ready, before your element is attached to native DOM. - Dmytro

2 Answers

4
votes

You can get the dom of Polymer by passing this and call the appendChild of the result, passing customElement:

Polymer.dom(this).appendChild(customElement);
-1
votes

Check out Polymer's selector. For locating dynamically-created nodes in your element’s local DOM, use the $$ method:

this.$$(selector)