← All topics

Angular Middle interview questions and answers

75 questions for a Angular (Middle) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.What changes when a component uses ChangeDetectionStrategy.OnPush?
  2. 2.Why doesn't this OnPush child update after the parent runs addItem()?
  3. 3.When do you need ChangeDetectorRef.markForCheck()?
  4. 4.What does ExpressionChangedAfterItHasBeenCheckedError mean?
  5. 5.How do signals improve change detection compared to plain fields?
  6. 6.Which is the best way to display data from an Observable in an OnPush component?
  7. 7.What does linkedSignal solve?
  8. 8.What does untracked() do inside a computed or effect?
  9. 9.How do you turn an Observable into a signal?
  10. 10.What does toObservable(sig) let you do?
  11. 11.What does model() create?
  12. 12.What is an input transform used for?
  13. 13.Which operator suits a search-as-you-type request so that only the latest query result is shown?
  14. 14.Which operator should handle a "Pay" button so double clicks don't send duplicate requests?
  15. 15.Which operator keeps several save requests strictly in order, one after another?
  16. 16.What is mergeMap best for?
  17. 17.Why add distinctUntilChanged() after debounceTime(300) in a search box?
  18. 18.How does BehaviorSubject differ from Subject?
  19. 19.Why does this code send two HTTP requests, and how do you fix it?
  20. 20.Why should catchError be placed inside switchMap in a long-lived stream?
  21. 21.What is the modern way to unsubscribe from an Observable when a component is destroyed?
  22. 22.What happens when a component lists a service in its providers?
  23. 23.Why use an InjectionToken?
  24. 24.What is the difference between useClass, useValue, useFactory and useExisting?
  25. 25.What does multi: true do in a provider?
  26. 26.How do you inject a dependency that might not be provided?
  27. 27.What happens when a lazy route declares providers?
  28. 28.How do you lazy-load a standalone component for a route?
  29. 29.What does a functional guard return to redirect the user?
  30. 30.How does canMatch differ from canActivate?
  31. 31.What is a resolver used for?
  32. 32.What does withComponentInputBinding() enable?
  33. 33.How do you warn the user before leaving a page with unsaved changes?
  34. 34.Why does a component not re-run ngOnInit when navigating from /users/1 to /users/2?
  35. 35.How do you write a custom synchronous validator?
  36. 36.Where should a "passwords must match" validator be attached?
  37. 37.How do async validators behave in Angular forms?
  38. 38.What is FormArray for?
  39. 39.What does nonNullable: true change in typed reactive forms?
  40. 40.What does implementing ControlValueAccessor allow?
  41. 41.How do you get a reference to a child element or component in the class?
  42. 42.How do you create several named slots for projected content?
  43. 43.What does this @defer block do?
  44. 44.What is the difference between pure and impure pipes?
  45. 45.What is the recommended way to bind to the host element of a component?
  46. 46.What is an attribute directive?
  47. 47.How do you add an auth header to every request?
  48. 48.How do you test a service that uses HttpClient without real network calls?
  49. 49.Why call fixture.detectChanges() in a component test?
  50. 50.When migrating to standalone, how do you keep using an NgModule-based library?
  51. 51.How does forkJoin differ from combineLatest?
  52. 52.How do you get a single value from an Observable with async/await?
  53. 53.How do you retry a failed HTTP request three times with a delay?
  54. 54.How does ReplaySubject(3) differ from BehaviorSubject?
  55. 55.What does the scan operator do?
  56. 56.How can a single request skip a functional interceptor (e.g. the auth header)?
  57. 57.What does provideHttpClient(withFetch()) change?
  58. 58.How do you render the same template fragment in several places of a component?
  59. 59.What does hostDirectives in a component or directive do?
  60. 60.How do you measure a DOM element's size after the component renders?
  61. 61.How do you register cleanup code from a service or a function without ngOnDestroy?
  62. 62.How do you expose a signal from a service without letting components change it?
  63. 63.How do you lazy-load a group of child routes?
  64. 64.How do you animate transitions between routes with the browser's View Transitions API?
  65. 65.What does redirectTo as a function allow?
  66. 66.How do you give an InjectionToken a default value without adding providers?
  67. 67.How do you create a component dynamically and set its inputs?
  68. 68.Which test runner do new Angular CLI projects use by default since v21?
  69. 69.How do you test an OnPush component after changing a signal input?
  70. 70.What does toSignal(obs$, { initialValue: [] }) change compared to toSignal(obs$)?
  71. 71.What is a rxResource (or resource) useful for compared to manual subscribe in effect?
  72. 72.Why avoid subscribe inside a component just to copy values into fields?
  73. 73.What is @defer (on viewport; prefetch on idle) for?
  74. 74.How do you pass a template from a parent to customize how a child renders each item?
  75. 75.How do you render a list of 10,000 rows without creating 10,000 DOM nodes?