मैंने दो कस्टम तत्वों (v1) के साथ वेब घटक का उपयोग करके एक साधारण उदाहरण बनाया है जहां एक दूसरे में घोंसला है। index.html:नेस्टेड तत्व (वेब घटक) को अपना टेम्पलेट नहीं मिल सकता है
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="import" href="app-container.html">
</head>
<body>
<app-container></app-container>
</body>
</html>
एप्लिकेशन-container.html:
<link rel="import" href="toolbar.html">
<template id="app-container">
<app-toolbar></app-toolbar>
</template>
<script>
customElements.define('app-container', class extends HTMLElement {
constructor() {
super();
let shadowRoot = this.attachShadow({ mode: 'open' });
const content = document.currentScript.ownerDocument.querySelector('#app-container').content;
shadowRoot.appendChild(content.cloneNode(true));
}
});
</script>
toolbar.html:
लेकिन toolbar.html document.currentScript
में अनुप्रयोग में रूप में ही है -container.html और इसलिए querySelector('#app-toolbar')
आईडी app-toolbar
के साथ टेम्पलेट नहीं मिल रहा है। इस समस्या को हल कैसे करें?
उदाहरण क्रोम 55 (पॉलीफिल के बिना) पर परीक्षण किया गया।
सुपरशेरप, बहुत धन्यवाद! नया साल मुबारक हो! –
धन्यवाद, आप भी! – Supersharp