According to the Polymer docs, the WebComponentsReady
event is necessary because...
The polyfills parse element definitions and handle their upgrade asynchronously. If you prematurely fetch the element from the DOM before it has a chance to upgrade, you’ll be working with an HTMLUnknownElement. In these situations, wait for the WebComponentsReady event before interacting with the element
I have an HTML page that imports a single web component and registers a handler that logs a statement when all web components are loaded:
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/platform/platform.js"></script>
<link rel="import" href="elements/my-element.html">
</head>
<body unresolved>
<my-element></my-element>
<script>
window.addEventListener('WebComponentsReady', function(e) {
console.log('components ready');
});
</script>
</body>
</html>
Why is the WebComponentsReady
event firing before my-element's ready
polymer event? I need to know when I can interact with the custom element, e.g. change its properties and call its public methods.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…