Mad*_*ddy 34 javascript angular
我正在学习Angular 2/4,我看到带有ng生成属性的html标签: _ngcontent-c0, _ngcontent-c1...
这个c值是什么意思?
Max*_*kyi 26
_ngcontent-c#
使用时添加属性ViewEncapsulation.Emulated
- 这是默认值.Angular使用这些属性来定位具有样式的特定元素.该数字c
是主机组件的唯一标识符.例如,如果您有两个具有以下模板的组件:
ComponentA
<span></span>
<comp-b></comp-b>
ComponenB
<h1></h1>
Run Code Online (Sandbox Code Playgroud)
角将迎来与内部组件样式的所有元素A
的_ngcontent-c0
和与内部组件样式的所有元素B
有_ngcontent-c1
:
<comp-a>
<span _ngcontent-c0></span>
<comp-b _ngcontent-c0>
<h1 _ngcontent-c1></h1>
</comp-b>
</comp-a>
Run Code Online (Sandbox Code Playgroud)
您可以通过在组件下面添加import来禁用它,
import {ViewEncapsulation} from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css'],
encapsulation: ViewEncapsulation.None
})
export class DashboardComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
请注意这一行:
encapsulation: ViewEncapsulation.None
Run Code Online (Sandbox Code Playgroud)
不从角度添加动态属性
归档时间: |
|
查看次数: |
23373 次 |
最近记录: |