_ngcontent-c#在Angular中意味着什么? [英] What does _ngcontent-c# mean in Angular?
问题描述
我正在学习Angular 2/4,我看到带有ng生成属性的html标签: _ngcontent-c0,_ngcontent-c1 ...
I'm learning Angular 2/4 and I see the html tags with the ng generated attributes: _ngcontent-c0, _ngcontent-c1...
这个c值是什么意思?
推荐答案
_ngcontent使用
属性 - 这是默认值。 Angular使用这些属性来定位具有样式的特定元素。数字 ViewEncapsulation.Emulated
时,会添加-c# c
是主机组件的唯一标识符。例如,如果您有两个包含以下模板的组件:
_ngcontent-c#
attributes are added when you use ViewEncapsulation.Emulated
- which is default. Angular uses these attributes to target specific elements with the styles. The number c
is sort of a unique identifier of the host component. For example, if you have two components with the following templates:
ComponentA
<span></span>
<comp-b></comp-b>
ComponenB
<h1></h1>
Angular将标记组件内部样式的所有元素 A
as _ngcontent-c0
以及组件 B
中带有 _ngcontent-c1的样式的所有元素
:
Angular will mark all elements with styles inside component A
as _ngcontent-c0
and all elements with styles inside component B
with _ngcontent-c1
:
<comp-a>
<span _ngcontent-c0></span>
<comp-b _ngcontent-c0>
<h1 _ngcontent-c1></h1>
</comp-b>
</comp-a>
这篇关于_ngcontent-c#在Angular中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!