【发布时间】:2023-11-28 17:34:01
【问题描述】:
我正在使用Angular10,而我的app-component.ts 如下所示:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.ShadowDom
})
我知道这将为组件的主机元素创建一个ShadowRoot。
现在,我在模板中添加input 元素,如下所示:
<div style='text-align: center'>
<h1>Parent Component</h1>
<br><br>
<label>Parent Component: </label>
<input type='text' #pInput name='myInput' />
<button (click)='getInfo(pInput)'>Get Info</button>
</div>
当我检查创建的 DOM 时,我看到为 input 元素添加了 shadow-root (user-agent)。
我的问题是为什么input 元素没有作为shadow-root (open) 的一部分添加?
什么情况下添加shadow-root(user-agent)?
【问题讨论】:
标签: javascript html css angular shadow-dom