Change Detection
Q1. How does change detection work?
Angular checks bindings in templates and updates the DOM when values changed. Traditionally zone.js triggers a check of the whole tree after any async event. With OnPush and signals only affected components are checked.
Q2. When does an OnPush component update?
- An input reference changes
- An event fires from the component or a child
- A signal read in its template changes
- An async pipe emits
markForCheck()is called
Q3. What does zoneless mean?
The app runs without zone.js, using provideZonelessChangeDetection(). Angular is notified by signals, events and the async pipe. It gives smaller bundles and more predictable updates.
Signals and RxJS
Q4. Signals vs RxJS?
Signals hold synchronous current state and are great for UI. RxJS models streams over time (events, HTTP, websockets) with powerful operators. Use toSignal and toObservable to bridge them.
**Q5. switchMap vs mergeMap vs concatMap vs exhaustMap?**
| Operator | Behavior | Use case |
|---|---|---|
switchMap | Cancel previous, keep latest | Search, route params |
mergeMap | Run all in parallel | Independent requests |
concatMap | One after another, in order | Ordered saves |
exhaustMap | Ignore new while one runs | Login or submit button |
Q6. How do you avoid memory leaks?
- Use the
asyncpipe ortoSignal(they unsubscribe automatically) - Use
takeUntilDestroyed()insubscribechains - Clean up timers and listeners in
DestroyRef.onDestroy - Remember HTTP Observables complete by themselves, but long streams do not
Q7. Hot vs cold Observables?
A cold Observable starts a new execution for each subscriber (HTTP). A hot one shares a source (events, Subjects). shareReplay can make a cold one shared.
Q8. Subject vs BehaviorSubject vs ReplaySubject?
Subject: no initial value, only new emissionsBehaviorSubject: needs an initial value and gives the latest to new subscribersReplaySubject(n): replays the last n values
**Q9. What are resource and httpResource?**
Signal-based async loaders that expose value, isLoading, error and reload, and refetch when their source signals change. They are best for reads; use HttpClient for writes.
**Q10. What is linkedSignal?**
A writable signal that resets from a source signal when it changes, for example a selected item that resets when the list changes, but can also be set manually.
Architecture
Q11. How do you structure a large Angular app?
- Feature folders with lazy routes
- A
corearea (auth, interceptors, singleton services) - A
sharedarea (reusable dumb components, pipes, directives) - Smart (container) components fetch data; dumb components get
input()s and emitoutput()s - Strict TypeScript and lint rules
Q12. State management options?
- Signals in services (simple and enough for most apps)
- NgRx SignalStore (structured, lighter)
- NgRx Store (large apps needing strict patterns, devtools, time travel)
Q13. Hierarchical injectors?
Angular has environment injectors (root, route) and element injectors (component and directive providers). Angular looks up the tree for a provider. Providing a service in a component gives each component instance its own copy.
**Q14. inject() vs constructor injection?**
inject() works in field initializers and in functions such as guards and interceptors, and makes inheritance and composition easier. Both do the same job.
Q15. Guards, resolvers and interceptors?
- Guards (
CanActivateFn,CanMatchFn,CanDeactivateFn) decide if navigation is allowed - Resolvers load data before a route is shown
- Interceptors (
HttpInterceptorFn) wrap every HTTP request
**Q16. canActivate vs canMatch?**
canActivate runs after the route is matched. canMatch decides whether the route can match at all, which also prevents loading its lazy code and allows alternative routes for the same path.
Performance and Rendering
Q17. How do you improve performance?
- Lazy load routes and use
@defer - OnPush, signals and
computed trackin@for, virtual scroll for long listsNgOptimizedImage- SSR or prerendering, bundle budgets and analysis
- Avoid heavy functions in templates
Q18. What is hydration and SSR?
SSR renders HTML on the server for fast first paint and SEO. Hydration lets the browser reuse that DOM instead of rebuilding it. Browser-only code must run inside afterNextRender or behind a platform check.
**Q19. What does @defer do?**
It lazy loads a block of the template and its dependencies on triggers such as on viewport or on interaction, with @placeholder, @loading and @error blocks.
Security and Testing
Q20. How does Angular prevent XSS?
It treats all bound values as untrusted and escapes or sanitizes them. Avoid bypassSecurityTrust* and direct innerHTML on elements.
Q21. Where should you store a JWT?
In an HttpOnly, Secure, SameSite cookie is safest against XSS. localStorage is simple but readable by scripts. Always use short lifetimes and validate on the server.
Q22. How do you test a component with an HTTP service?
Provide a mock service with useValue, or use provideHttpClientTesting and HttpTestingController to check and answer requests. Verify with httpMock.verify().
**Q23. What are content projection and ng-template vs ng-container?**
ng-contentprojects parent content into a componentng-templatedefines a template that renders only when usedng-containeris a grouping element that adds nothing to the DOM
**Q24. What is ExpressionChangedAfterItHasBeenCheckedError?**
A development error that appears when a value changes during a change detection run, often from changing parent state in a child's lifecycle hook. Fix with signals, moving the logic earlier, or restructuring state.
Q25. How do you upgrade Angular?
Use ng update one major version at a time, follow the official Update Guide, run migration schematics and tests after each step.
track and OnPush. Stories make answers memorable.
Conclusion
Advanced answers connect concepts: signals and OnPush for speed, RxJS for streams, lazy loading and SSR for loading time, and clean architecture for large teams.

