Bird
0
0

Which of the following is the correct syntax to create an Effect in Angular using createEffect?

easy📝 Syntax Q3 of 15
Angular - Signals
Which of the following is the correct syntax to create an Effect in Angular using createEffect?
AloadData$ = createEffect(this.actions$.pipe(ofType(load), map(() => this.api.getData())));
BloadData$ = createEffect(() => this.actions$.pipe(ofType(load), switchMap(() => this.api.getData())));
CloadData$ = createEffect(() => this.api.getData().pipe(ofType(load)));
DloadData$ = createEffect(() => this.actions$.pipe(map(load), switchMap(() => this.api.getData())));
Step-by-Step Solution
Solution:
  1. Step 1: Check the correct use of createEffect

    The effect must be a function returning an observable from this.actions$ piped through ofType and then a flattening operator like switchMap.
  2. Step 2: Identify the correct chaining and operators

    loadData$ = createEffect(() => this.actions$.pipe(ofType(load), switchMap(() => this.api.getData()))); correctly uses createEffect(() => this.actions$.pipe(ofType(load), switchMap(...))). Other options misuse operators or pipe placement.
  3. Final Answer:

    loadData$ = createEffect(() => this.actions$.pipe(ofType(load), switchMap(() => this.api.getData()))); -> Option B
  4. Quick Check:

    Effect syntax = createEffect with actions$.pipe and ofType [OK]
Quick Trick: createEffect needs a function returning actions$.pipe(...) [OK]
Common Mistakes:
  • Passing observable directly instead of a function
  • Using map instead of switchMap for async calls
  • Placing ofType after API call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes