Ready event for dynamic add polymer elements

Viewed 528

How do I know when a polymer element is ready? Giving that:

It is dynamically added, as:

var ele = document.createElement('my-custom-element');
document.body.appendChild(ele);

So now when I call ele.myCustomMethod() it will fail because it is not ready yet (in FF/IE/Safari with webcomponent-lite.js)

What I am doing right now is call this.fire('ready') inside the polymer element ready() function, and listen to it ele.addEventListener('ready', ()=>{ele.myCustomMethod();})

But this make all code very hard to write. And sometimes I use $(body).html('<my-custom-element />'), and it make things more complicated.

My question is: Is there any better way to do that?

Thank you.

1 Answers
Related