Model answers for 4 Angular questions
Typical round: concepts, RxJS scenario, a component task
Q: What does OnPush change detection do? A: The component is checked only when an input reference changes, an event fires inside it, an async pipe emits, a signal it reads changes, or you mark it for check. It skips many unnecessary checks, but you must treat inputs as immutable.
Q: switchMap vs mergeMap? A: switchMap cancels the previous inner observable when a new value arrives, ideal for search-as-you-type. mergeMap runs all inner observables concurrently, useful when every request must complete. concatMap queues them in order.
Q: What are signals? A: Reactive values introduced in Angular 16. Reading a signal in a template or computed() tracks it, and updating it notifies only dependants. They simplify state and enable finer-grained change detection than zone-based checks.
Q: How do you avoid memory leaks with subscriptions? A: Prefer the async pipe, use takeUntilDestroyed() or a destroy notifier, and avoid manual subscriptions in components where a template binding works.