Explain style encapsulation modes.
Skip to solutionKEEP THE
hardFrontend
What is ViewEncapsulation in Angular?
485 views
01
Understand the problem
view-encapsulation
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
ViewEncapsulation controls how component styles are scoped: Emulated (default — Angular adds attributes so styles don't leak), None (global styles), and ShadowDom (native Shadow DOM isolation).
Solution ready — 2 min read
Classified // press E to declassify
04
Read the code
Setting the encapsulation mode
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-badge',
standalone: true,
template: '<span class="badge">New</span>',
styles: ['.badge { color: crimson; font-weight: 700; }'],
// Emulated (default) → scoped; None → global; ShadowDom → native isolation
encapsulation: ViewEncapsulation.Emulated,
})
export class BadgeComponent {}05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 102 of 121 decoded in the Angular track. One more won't hurt.