Angular Interview Questions: Intermediate and Advanced

Angular 16 min min read Updated: Nov 16, 2026 Advanced
Angular Interview Questions: Intermediate and Advanced
Advanced Topic 2 of 3

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?**

OperatorBehaviorUse case
switchMapCancel previous, keep latestSearch, route params
mergeMapRun all in parallelIndependent requests
concatMapOne after another, in orderOrdered saves
exhaustMapIgnore new while one runsLogin or submit button

Q6. How do you avoid memory leaks?

  • Use the async pipe or toSignal (they unsubscribe automatically)
  • Use takeUntilDestroyed() in subscribe chains
  • Clean up timers and listeners in DestroyRef.onDestroy
  • Remember HTTP Observables complete by themselves, but long streams do not
typescript this.route.params.pipe(takeUntilDestroyed()).subscribe(...)

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 emissions
  • BehaviorSubject: needs an initial value and gives the latest to new subscribers
  • ReplaySubject(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 core area (auth, interceptors, singleton services)
  • A shared area (reusable dumb components, pipes, directives)
  • Smart (container) components fetch data; dumb components get input()s and emit output()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
  • track in @for, virtual scroll for long lists
  • NgOptimizedImage
  • 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-content projects parent content into a component
  • ng-template defines a template that renders only when used
  • ng-container is 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.

Show experience: Mention a real problem you solved, for example a slow list fixed by 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.

Quick Summary: Know change detection, RxJS flattening operators, memory leaks, DI, performance, SSR and testing.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators