Q1
Why does RxJS switchMap fix race conditions in Angular typeahead search, while mergeMap can corrupt order?
switchMap automatically cancels the previous in-flight HTTP Observable whenever a new search keystroke arrives. mergeMap runs all requests concurrently and emits whichever responds last—overwriting newer queries.
Q2
Why can mutating an array item in-place (items.push(x)) fail to update an Angular component using ChangeDetectionStrategy.OnPush?
OnPush only triggers view checks when @Input() object *references* change, async pipes emit, or DOM events fire inside the component. Always emit immutable array/object copies ([...items, x]).
Q3
What causes memory leaks in Angular components if you subscribe inside ngOnInit, and how do async pipe or takeUntilDestroyed prevent them?
Long-lived streams (router events, timers, subjects) stay subscribed after the component is destroyed, holding closed-over DOM references in RAM. Using the async pipe or Angular's takeUntilDestroyed() auto-unsubscribes cleanly.
Q4
What is the key behavioral difference between Subject, BehaviorSubject, and ReplaySubject in Angular state services?
Subject only emits values pushed *after* subscribing; BehaviorSubject stores an initial value and emits the latest value immediately to new subscribers; ReplaySubject(n) replays the last n emissions.
Q5
Why must Angular HttpInterceptor clone the HttpRequest (req.clone(...)) instead of mutating headers directly?
Angular treats HttpRequest instances as immutable so retries or error interceptors can safely replay the exact original request without side-effect corruption.
Q6
When should you use CanActivate vs CanMatch route guards in modern Angular?
CanActivate decides access *after* loading lazy bundles, whereas CanMatch evaluates *before* downloading a lazy chunk or choosing between same-path role routes—saving bundle bandwidth and enabling clean fallback routing.
Q7
Why does ngOnChanges NOT trigger when an @Input() object's nested property changes?
Angular performs shallow === reference equality checks on @Input() bindings. Mutating user.name leaves the user reference unchanged, so ngOnChanges won't fire unless a new object reference is passed.
Q8
How do Angular Signals improve granular reactivity compared to Zone.js dirty-checking?
Zone.js triggers broad component-tree checks on async events. Signals track exact template signal reads, allowing fine-grained dependency updates and paving the way for zoneless Angular apps.
Q9
Why is omitting trackBy (or @for ... track) on large *ngFor lists a major performance killer?
Without a stable track key, replacing an array destroys and recreates every DOM node from scratch, losing focus, scroll position, and CSS transition states.
Q10
What is the difference between ViewEncapsulation.Emulated and None regarding component CSS leaks?
Emulated (default) scopes CSS rules with generated _ngcontent-* attributes so styles stay local. None injects rules globally into <head>, potentially overriding unrelated routes.