Bird
0
0

Which of the following is the correct way to create an Effect in Angular using RxJS operators?

easy📝 Syntax Q12 of 15
Angular - Signals
Which of the following is the correct way to create an Effect in Angular using RxJS operators?
AcreateEffect(() => this.actions$.subscribe(action => console.log(action)))
BcreateEffect(() => this.actions$.map(action => action.type))
CcreateEffect(() => this.actions$.pipe(ofType(loadData), tap(() => console.log('Loading'))))
DcreateEffect(() => this.actions$.filter(action => action.type === 'loadData'))
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct RxJS operators for Effects

    Effects use pipe with operators like ofType to filter actions and tap for side effects.
  2. Step 2: Check each option's syntax

    createEffect(() => this.actions$.pipe(ofType(loadData), tap(() => console.log('Loading')))) correctly uses pipe, ofType, and tap. Others misuse operators or subscribe directly, which is incorrect inside Effects.
  3. Final Answer:

    createEffect(() => this.actions$.pipe(ofType(loadData), tap(() => console.log('Loading')))) -> Option C
  4. Quick Check:

    Effect uses pipe + ofType + tap [OK]
Quick Trick: Use pipe with ofType and tap inside createEffect [OK]
Common Mistakes:
  • Using subscribe inside createEffect
  • Using map instead of tap for side effects
  • Using filter without ofType

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes