I’ve made a custom template that relies on a function call from the constructor to set up the component after the template has been added to the shadow dom. I’m trying to use some SVG and hence cannot use the ElementAPI methods thus wrapping SVG.js in a polymer element.
If I use getElement().callFunction(“example”) in the constructor the this.$ is undefined at that point of time.
How can I make the function call during component construction and still access the template DOM?
The way I get around it at the moment is to create a new Div rather than reference the template and then
in after my constructor function,
initFunctionCall(){
this.newDiv = document.createElement("div");
// use new div in a non Element API Class.
}
afterServerUpdate(){
this.$.templateDiv.appendChild(this.newDiv);
}
Thanks heaps
p.s sorry about the “ha” in the heading. Not sure why that’s there.
In my code the dom-repeat was generating a number of paper-toggle-buttons which I needed to add listeners to.
If you add the following method to you polymer component class then it will be called after the dom-repeat elements have been rendered.
afterServerUpdate()
{
let obj = this;
// The call to querySelectorAll will now succeed.
let elems = this.shadowRoot.querySelectorAll("paper-toggle-button");
}