Dynamically append child element on load in Polymer 2.0

Viewed 735

I'm trying to upgrade to Polymer 2.0 and I can't seem to append child elements on a parent element's load like I could in 1.X. Previously, I think I just used the ready callback, but it seems all the callbacks have changed.

Seen here in the Callback contracts have changed section.

I've tried running

document.getElementById("parent-element").appendChild(document.createElement("child-element"));

on ready and attached, yet it seems to be executing the line before parent-element is even created. This causes an exception:

TypeError: Cannot read property 'appendChild' of null

I've also tried using

this.$.container.appendChild(document.createElement("child-element"));

where container is the id of an empty <div> inside the parent element, but I get the same issue. I'm pretty new to Polymer, so if there's a better method or structure I can use to get what I need, let me know.

1 Answers
Related