Bird
0
0

Given this effect code snippet:

medium📝 component behavior Q13 of 15
Angular - State Management
Given this effect code snippet:
loadData$ = createEffect(() => this.actions$.pipe(
  ofType(loadData),
  switchMap(() => this.api.getData()),
  map(data => loadDataSuccess({ data })),
  catchError(() => of(loadDataFailure()))
));

What happens when the loadData action is dispatched?
AThe API call is ignored and no action is dispatched
BThe effect causes a syntax error and stops
COnly <code>loadDataFailure</code> action is dispatched immediately
DThe API call is made, and on success, <code>loadDataSuccess</code> action is dispatched
Step-by-Step Solution
Solution:
  1. Step 1: Understand the effect flow

    When loadData action is dispatched, the effect listens and triggers the API call via switchMap.
  2. Step 2: Analyze success and error handling

    On success, map dispatches loadDataSuccess with data; on error, catchError dispatches loadDataFailure.
  3. Final Answer:

    The API call is made, and on success, loadDataSuccess action is dispatched -> Option D
  4. Quick Check:

    Effect triggers API and dispatches success or failure [OK]
Quick Trick: Effects dispatch success or failure actions after API calls [OK]
Common Mistakes:
  • Assuming no action is dispatched after API call
  • Confusing map with catchError behavior
  • Thinking effect causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes