Bird
0
0

You want to log each value emitted by an HTTP request observable without changing the data. Which is the best way to do this using tap? Consider this code:

hard🚀 Application Q15 of 15
Angular - RxJS Operators
You want to log each value emitted by an HTTP request observable without changing the data. Which is the best way to do this using tap? Consider this code:
this.http.get('/api/data').pipe(
  // What goes here?
).subscribe(data => this.process(data));
Asubscribe(data => console.log('Received:', data))
Bmap(data => { console.log('Received:', data); return data; })
Ctap(data => console.log('Received:', data))
Dfilter(data => { console.log('Received:', data); return true; })
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    You want to log data without changing it before passing it to subscribe.
  2. Step 2: Choose the operator that logs without modifying

    tap is designed for side effects like logging without altering data. map transforms data, filter filters it, and logging inside subscribe happens after pipe.
  3. Final Answer:

    tap(data => console.log('Received:', data)) -> Option C
  4. Quick Check:

    tap logs side effects without data change [OK]
Quick Trick: Use tap inside pipe for logging without data change [OK]
Common Mistakes:
MISTAKES
  • Using map for logging (changes data)
  • Logging inside subscribe instead of pipe
  • Using filter which may drop data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes