Angular Web Framework State Management & Change Detection 2 — Questions and Answers
Question 1: In the Flux/Redux pattern used by NgRx, what is the single source of truth for application state?
- Service
- Component
- Store (Correct answer)
- Reducer
Correct answer: Store
The Store is an immutable, single source of truth that holds the entire application state tree.
Question 2: Which Angular signal API creates a writable reactive value introduced in Angular 16+?
- computed()
- effect()
- signal() (Correct answer)
- toSignal()
Correct answer: signal()
signal() creates a writable reactive primitive that Angular tracks for fine-grained change detection.
Question 3: What is the purpose of the computed() function in Angular Signals?
- Create a writable signal
- Run side effects when signals change
- Derive a read-only value from one or more signals (Correct answer)
- Convert an Observable to a signal
Correct answer: Derive a read-only value from one or more signals
computed() creates a lazily evaluated, memoized read-only signal derived from other signals.
Question 4: Which function converts an RxJS Observable into an Angular Signal?
- fromSignal()
- toObservable()
- toSignal() (Correct answer)
- signalFrom()
Correct answer: toSignal()
toSignal() from @angular/core/rxjs-interop subscribes to an Observable and exposes its latest value as a Signal.
Question 5: In Angular's default change detection, what triggers the detection cycle?
- Only manual calls to detectChanges()
- Only HTTP responses
- Async events like DOM events, timers, and HTTP responses via Zone.js (Correct answer)
- Only input property changes
Correct answer: Async events like DOM events, timers, and HTTP responses via Zone.js
Zone.js patches async APIs so Angular is notified whenever any async event completes, triggering a top-down change detection pass.
Question 6: What NgRx operator is used inside createEffect() to handle errors without killing the effect stream?
- catchError with EMPTY or of() (Correct answer)
- throwError()
- retry()
- finalize()
Correct answer: catchError with EMPTY or of()
Using catchError inside the inner Observable (not the outer stream) and returning EMPTY or a fallback action keeps the effect alive after an error.
In the Flux/Redux pattern used by NgRx, what is the single source of truth for application state?