简体   繁体   English

Svg 未显示 - shadow-root

[英]Svg is not displaying - shadow-root

I have a <template> with an SVG inside it and I am trying to add the template to the DOM.我有一个<template> ,里面有一个 SVG,我正在尝试将模板添加到 DOM。 The template is added successfully - but the svg is hidden for some reason.模板已成功添加 - 但 svg 由于某种原因被隐藏。 Without templates, it works fine!没有模板,它工作正常!

HTML : HTML

<div id="output"></div>

<template id="template">
    <li>
        <svg class="...>
            <use href="./icons.svg#icon"></use>
        </svg>
        <span></span>
    </li>
</template>

JS : JS

const $output = document.getElementById('output');

// Clone template of auto complete addresses container
const $otherTemplate = $other.content.firstElementChild.cloneNode(true);

// Select the list container inside the template
const $list = $otherTemplate.querySelector('ul')

const $template = document.getElementById('template');

const $sugTemplate = $template.content.firstElementChild.cloneNode(true);

$list.appendChild($sugTemplate);

$output.appendChild($otherTemplate);

RESULT :结果

在此处输入图像描述

That's a chrome bug.那是一个铬错误。

Bug report has been created: https://bugs.chromium.org/p/chromium/issues/detail?id=1099181已创建错误报告: https://bugs.chromium.org/p/chromium/issues/detail?id=1099181

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM