angular:HtmlElement的子节点有Shadow dom时奇怪的现象

发布于:2023-09-16 ⋅ 阅读:(49) ⋅ 点赞:(0)

描述:

        这样写时,会自动跳过shadow dom节点的遍历

const cloneElement = this.contentElement.cloneNode(true) as HTMLElement;
for(let childNodeIndex = 0; childNodeIndex < cloneElement.childNodes.length; childNodeIndex++) {
    element.appendChild(cloneElement.childNodes[childNodeIndex] as HTMLElement);
}

           或者使用cloneElement.childNodes.forEach遍历,也不会遍历到shadow dom节点

        如果这样写:

                会在appendChild shadow dom节点报错,提示不是一个HtmlElement,无法append

const cloneElement = this.contentElement.cloneNode(true) as HTMLElement;
const childCount = cloneElement.childNodes.length;
for(let childNodeIndex = 0; childNodeIndex < childCount; childNodeIndex++) {
    element.appendChild(cloneElement.childNodes[childNodeIndex] as HTMLElement);
}


网站公告

今日签到

点亮在社区的每一天
去签到