Question presented to candidate:
"Two teams both style a .label class in their own components, and one team's styles keep showing up in the other team's screens. Explain what ViewEncapsulation is, what the options are, and which component is the likely culprit."
What a strong answer should cover:
ViewEncapsulationcontrols whether a component'sstylesapply only to its own template or to the whole page; it is set per component in@Component({ encapsulation }).- Emulated (default): Angular rewrites selectors with generated attributes so they only match elements in that component's template.
- ShadowDom: uses the browser's real Shadow DOM, styles live inside the component's shadow root; None: styles are added to the document as written and are global.
- The likely culprit is a component with
ViewEncapsulation.None(or::ng-deep); its rules apply everywhere, including inside other Emulated components. - Encapsulation stops styles leaking out; it does not stop global styles leaking in (except Shadow DOM, partly).
- Mention
ExperimentalIsolatedShadowDom(experimental since v21) and that styles must be statically analysable for AOT.
Clarifying questions expected:
- "Are any components using
encapsulation: ViewEncapsulation.Noneor::ng-deep?" - "Do the leaking rules come from component styles or from global stylesheets?"
Code / implementation expected: Optional β two components with the same class name, one Emulated and one None, showing the leak.