Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下问题询问“如何在 Angular 组件测试中查询 shadowDOM ”,但我不想在单元测试上下文中实现这一点,而是在实际组件中实现。
具体来说,我有一个组件,其模板包含一个我想要引用的画布。
您可以扩展ShadowRootAware和覆盖onShadowRoot()以获取对 的引用ShadowRoot,该引用又可用于查询。(使用.querySelector)
ShadowRootAware
onShadowRoot()
ShadowRoot
.querySelector