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

描述:

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

TypeScript 复制代码
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

TypeScript 复制代码
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);
}
相关推荐
qq4356947012 分钟前
Vue04
前端·vue.js
Yeats_Liao1 小时前
Feed流系统设计(三):数据模型与存储设计,从表结构到Redis收件箱
java·javascript·redis
我是真菜1 小时前
彻底理解js中的深浅拷贝
前端·javascript
江畔柳前堤1 小时前
github实战指南07-CLI 与高级技巧
前端·人工智能·chrome·深度学习·github·caffe·issue
kisdiem2 小时前
ReAct:让大模型一边推理,一边行动
前端·react.js·前端框架
西部荒野子2 小时前
JS 如何跑进两个原生世界
前端
RANxy2 小时前
AntV 入门系列第一篇:从零开始的数据可视化之旅
前端
小小小小宇3 小时前
前端 WebRTC 全解析与应用
前端
华玥3 小时前
优化滚动列表,使用虚拟滚动
前端
小小小小宇3 小时前
前端 WebAssembly 全解析与应用
前端