Question presented to candidate:
"In a component stylesheet, what do :host, :host-context() and ::ng-deep each target? Show me how you would theme a panel for dark mode and restyle a library chip inside it, and tell me what Angular turns those selectors into."
What a strong answer should cover:
:hosttargets the component's own host element (which a template selector cannot reach);:host(.active)adds a condition on the host itself.:host-context(.dark)applies when the host or any ancestor matches.dark; handy for themes set onbodyor a wrapper.::ng-deepturns off encapsulation for the rest of the selector, so it reaches into child components (and, without a prefix, the whole page).- With Emulated encapsulation Angular compiles them to attribute selectors:
:hostto[_nghost-β¦],:host-context(.dark) h3to two selectors (.dark[_nghost-β¦] h3[β¦]and.dark [_nghost-β¦] h3[β¦]),::ng-deepdrops the_ngcontentrequirement after it. - Always prefix
::ng-deepwith:hostto keep it inside your subtree; it is discouraged by the Angular docs and kept for backwards compatibility; prefer CSS custom properties or inputs. - Specificity still matters: a
::ng-deeprule can tie with the child's own rule and lose on order.
Clarifying questions expected:
- "Do we own the child component, or is it a third-party library?"
- "Is dark mode a class on
body, on a wrapper, or a media query?"
Code / implementation expected: Yes β a panel using all three, with the compiled CSS shown.