angular - 如何访问shadowdom中的元素
问题描述
我只想访问 shadow-root 中的元素。在我的 Angular 应用程序中,我的一个组件用shadowDom封装。
@component({
selector: "app-home",
templateUrl: "./home.component.html",
styleUrls: ["./home.component.scss"],
encapsulation: ViewEncapsulation.ShadowDom
})
当我为应用程序提供服务时,这就是渲染元素的样子
<body class>
<app-root _nghost-c0 ng-version="7.0.3">
<router-outlet _ngcontent-c1=""></router-outlet>
<app-home>
#shadow-root (open) <== shadow-root
<style>...</style>
<style>...</style>
<div id="main">
<section id="one">
<app-github-calendar _nghost-c3>
<div _ngcontent-c3 class="calendar"> Loading the data just <== this element
for you.</div>
</app-github-calendar>
</section>
</app-home>
我试图获取“日历”元素 ussign javascript querySelector、getElementsByClassName、querySelectorAll等,但我无法获取元素。
告诉我如何得到它。
解决方案
推荐阅读
- r - binomial()$linkinv(fixef()) 和 binomial_pred_ci() 函数:这些函数在应用于混合广义分析时到底有什么用?
- django - Django:“缺少1个必需的位置参数:'lookup _name'”,当它没有丢失时?
- c# - 在 ASP.NET Core Web API 应用程序中禁用 Ctrl+C 关闭
- r - 为 GitHub 操作安装 lintr
- c# - How do I create a Windows installer for .net core web application that runs as a service?
- android - How can i stop exoplayer in viewpager2 on swipe
- reactjs - How can I pass values from component from A to B component in react?
- html - 为什么 form method=post 重置数据实例?
- asp.net-core - 如何从 .net 核心中的 jwt 令牌中获取用户的 id 或如何从自定义授权属性返回值?
- plotly - 在 Plotly 地理图中将海洋颜色设置为透明