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);
}
相关推荐
BUG收容所所长1 分钟前
二分查找的「左右为难」:如何优雅地找到数组中元素的首尾位置
前端·javascript·算法
彬师傅1 分钟前
geojson、csv、json 数据加载
前端
用户52709648744901 分钟前
🔥 我与 ESLint 的爱恨纠葛:从"这破玩意儿"到"真香警告"
前端
梨子同志2 分钟前
手动实现 JavaScript 的 call、apply 和 bind 方法
前端·javascript
梨子同志3 分钟前
ES6 let 和 const
前端·javascript
用户5806139393004 分钟前
超越 console.log():前端调试的 10 个神级技巧
前端
却尘5 分钟前
当全世界都在用 Rust 重写一切时,Prisma 却选择了反方向
前端·数据库·orm
这是个栗子5 分钟前
前端开发者常用网站
前端
前端小白佬21 分钟前
【JS】防抖(debounce)和节流(throttle)
前端·面试
GIS之路23 分钟前
OpenLayers 从后端服务加载 GeoJSON 数据
前端