2

I try to make a simple webcomponent (with webcomponents.js v 0.7.23). This component has a method (setTitre()). If I call this method in my HTML page at startup, Chrome is ok but FF and IE say that the function is undefined. If I call this method from the console (document.querySelector('hello-world').setWho('new')), it's ok in all browsers.

Code is here : https://github.com/olofweb/Webcomponents

Olof
  • 524
  • 5
  • 20
  • Possible duplicate of [How to execute a script when the custom element is upgraded](http://stackoverflow.com/questions/35805252/how-to-execute-a-script-when-the-custom-element-is-upgraded) – Supersharp Jan 27 '17 at 09:25

1 Answers1

4

With the webcomponentsjs polyfill, you need to wait for the WebComponentsReady event before calling a custom element method:

document.addEventListener( 'WebComponentsReady', function () 
{
    document.querySelector('hello-world').setTitre()
} )

It's due to the asynchronous upgrading of the custom elements when using the non-native implementation.

Supersharp
  • 29,002
  • 9
  • 92
  • 134