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