I'm using Web Components v1.
Suppose two Custom Elements:
parent-element.html
<template id="parent-element">
<child-element></child-element>
</template>
child-element.html
<template id="child-element">
<!-- some markup here -->
</template>
I'm trying to use connectedCallback in parent-element to initialise the entire parent/child DOM structure when it is attached, which requires interaction with methods defined in child-element.
However, it seems child-element isn't properly defined at the time connectedCallback gets fired for customElement:
parent-element.js
class parent_element extends HTMLElement {
connectedCallback() {
//shadow root created from template in constructor previously
var el = this.shadow_root.querySelector("child-element");
el.my_method();
}
}
This will not work, because el is an HTMLElement and not a child-element as expected.
I need a callback for parent-element once all child custom elements in its template have been properly attached.
The solution in this question does not seem to work; this.parentElement is null inside child-element connectedCallback().
ilmiont