I’m putting a custom element in a template and then “selecting” it out to Window level. It seem to loose its identity as a custom element.
// In page
<template id="holder">
<my-element field="A"></my-element>
</template>
<script type="module">
class MyElement extends HTMLElement {
constructor() {
super();
}
get Field() { return this.getAttribute("field");}
}
window.customElements.define("my-element", MyElement);
</script>
<script>
const frag = document.querySelector("#holder").content;
const el = frag.querySelector("my-element");
console.log({el});
</script>
When <my-element>
is a page level and not in a template I can read xxx.Field
. When it comes from within a template it seems to no longer act like the custom element - xxx.Field isn’t defined. The script and selecting it and custom elements are both at “Window” level, so shouldn’t it “cast” correctly without having to be attached to document?