- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在我当前的 Angular 7 应用程序中,我们正在努力处理来自库的组件,它需要一些 css 资源。我们不想将这些资源应用到我们应用程序的所有其余部分,而是应用到一个特定的组件,它的子组件和孙组件。
在我们的研究过程中,我们发现了这两个有趣的选项:
encapsulation: ViewEncapsulation.Native
和:
encapsulation: ViewEncapsulation.ShadowDom
因此,它们似乎都使用了浏览器的 shadow dom 实现。
这些选项之间有什么区别?
最佳答案
这几天前一直困扰着我,然后我意识到它们收敛了一点但不完全。实际上的差异是关于 the newer version of shadowDOM (v1)
。如您所见 here 在 angular 的代码源中,他们为 ViewEncapsulation.ShadowDom
添加了另一个条件。 :
Here they share the same return
case ViewEncapsulation.Native:
case ViewEncapsulation.ShadowDom:
return new ShadowDomRenderer(this.eventManager, this.sharedStylesHost, element, type);
And then they check whether it is ViewEncapsulation.ShadowDom or not (else condition)
if (component.encapsulation === ViewEncapsulation.ShadowDom) {
this.shadowRoot = (hostEl as any).attachShadow({mode: 'open'});
} else {
this.shadowRoot = (hostEl as any).createShadowRoot();
}
因此, ViewEncapsulation.ShadowDom
是向 ShadowDOM V1 添加支持的步骤,可能 弃用 ViewEncapsulation.Native
描述 here:
ViewEncapsulation.Shadow is added as a new API, rather than changing the behavior of the ViewEncapsulation.Native option, which could lead to unexpected results for developers currently using the v0 API. This should (eventually?) deprecate the ViewEncapsulation.Native option.
关于angular - Native 和 ShadowDom ViewEncapsulation 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53409943/
我正在通过制作一个简单的 webapp 来学习 Dart。我想到的应用程序 ui 有两个部分,一个是控制面板,另一个是工作区。通过单击控制面板中的按钮,用户应该能够控制工作区。 控制面板和工作区都是定
Angular 的 ViewEncapsulation.ShadowDom 与 ViewEncapsulation.Emulated 有什么区别? 我了解 ViewEncapsulation.None
一开始我想说我知道这个问题类似于: How to let imported css font / icons have effects on elements in the shadow dom? 事
外部 ShadowDOM 和内部 ShadowDOM 之间的 CSS 空间是分开的。 .foo a.bar { text-decoration: none; color: skyblue;
在 Rob Dodson 关于 Web Components 的演讲之后,他提到了全新的“cat”^^ 和“hat”^ CSS 选择器,我问过关于将样式不仅应用于自定义元素的 ShadowDOM,还应
我最近开始接触 WebComponents,我必须说到目前为止我发现它具有开创性!为了更好地理解这个概念,我尝试将我早期元素中的设计应用到可重用的 Web 组件中。我首先尝试创建一个具有一些附加功能的
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 7年前关闭。 Improve this
问题的答案Cascading style sheets use "id" or "class"表示 id 的 Put an ID on an element if "it is the ..." (e
我正在设计 Chrome 扩展程序。我希望能够更改选项卡中显示的标题而不更改真实的 标签。在后台脚本中,您可以将标题作为只读值进行访问。通常,您使用内容脚本并更改实际的 标签。 我正在尝试使用 Sha
可能是个简单的问题,但我还没有真正找到答案: ShadowDOM 或 WebComponents(作为更大的标准)实际上是否也封装了 JavaScript?就像每个组件都有单独的 namespace
尝试更改封装时,会出现 Emulated、Native、None 和最后一个新的“ShadowDom”4 个选项。我知道 ViewEncapsulation.Native用于使用 Shadow DOM
如何获取对 Angular 组件中封装设置为 ShadowDOM 的元素的引用? const element = document.getElementById(id); 例如返回null 编辑:添加
我一直在使用 FAST 工具包 ( https://fast.design ) 创建我自己希望使用的元素。在这段旅程中,我制作了一个工具栏。 作为一个工具栏,我想将按钮的背景更改为透明(看起来像: h
我想做一个 Angular 7 应用程序,将所有 encapsulation 设置为 ViewEncapsulation.ShadowDom - 这一切都很好很好。 但我似乎找不到任何可靠的引用资料来
我一直在使用 FAST 工具包 ( https://fast.design ) 创建我自己希望使用的元素。在这段旅程中,我制作了一个工具栏。 作为一个工具栏,我想将按钮的背景更改为透明(看起来像: h
我无法让我的 div 移动。它是一个自定义元素,由事件监听器创建。这两个自定义元素都有自己的 shadowdom。 树状结构 第一个自定义元素是/WebDesktop.js第二个元素是/应用程序窗口.
我想要一些关于如何设置 font-size 的想法到 ,动态地(即从 JS 而不是 CSS 设置 font-size)。 文档中没有 font-size 的默认属性。 看起来只能通过 mixin 设
虽然这似乎是一个重复的问题,但之前提出的那些问题都是基于 Polymer,而不是原生的 CustomElements,而且这是关于 css 本身,而不是渗透 ShadowDOM 或自定义 CSS 属性
我正在构建一个利用 d3.js 进行数据可视化的工具。该工具依赖于 webcomponentss 和 shadowDOM。 d3.js 无法仅通过 d3.select 选择 shadowDOM 中的任
在我当前的 Angular 7 应用程序中,我们正在努力处理来自库的组件,它需要一些 css 资源。我们不想将这些资源应用到我们应用程序的所有其余部分,而是应用到一个特定的组件,它的子组件和孙组件。
我是一名优秀的程序员,十分优秀!