What does :host /deep/ selector mean?

被刻印的时光 ゝ 提交于 2019-11-29 16:25:45

问题


Please explain in a straightforward way what :host /deep/ means:

:host /deep/ .ui-autocomplete {
  width: 85%;
}

回答1:


It is used to allow styling child components when using emulated view encapsulation.

More about this can be found here:

https://angular.io/guide/component-styles

Btw /deep/ selector is now deprecated:

The shadow-piercing descendant combinator is deprecated and support is being removed from major browsers and tools. As such we plan to drop support in Angular (for all 3 of /deep/, >>> and ::ng-deep). Until then ::ng-deep should be preferred for a broader compatibility with the tools.

:host is used to address the hosting element - that is the one that you use to add the component somewhere (e.g. <app-component>).

Use the :host pseudo-class selector to target styles in the element that hosts the component (as opposed to targeting elements inside the component's template).

So the selector :host /deep/ .ui-autocomplete means "on current hosting element, go deep (search in child components too) and look for elements with class ui-autocomplete.

Here is some additional information about the view encapsulation feature:

https://blog.thoughtram.io/angular/2015/06/29/shadow-dom-strategies-in-angular2.html



来源:https://stackoverflow.com/questions/46914414/what-does-host-deep-selector-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!