Bird
0
0

Consider the following Angular RxJS code:

medium📝 component behavior Q5 of 15
Angular - RxJS Operators
Consider the following Angular RxJS code:
import { of, interval } from 'rxjs';
import { concatMap, take, map } from 'rxjs/operators';

of('A', 'B').pipe(
  concatMap(letter => interval(20).pipe(take(3), map(i => letter + i)))
).subscribe(console.log);

What will be the order of emitted values?
AB0, A0, B1, A1, B2, A2
BA0, B0, A1, B1, A2, B2
CB0, B1, B2, A0, A1, A2
DA0, A1, A2, B0, B1, B2
Step-by-Step Solution
Solution:
  1. Step 1: Understand concatMap

    concatMap queues inner observables and subscribes to them one after another.
  2. Step 2: Analyze emissions

    First, 'A' triggers interval emitting A0, A1, A2 sequentially; only after completion does 'B' start emitting B0, B1, B2.
  3. Final Answer:

    A0, A1, A2, B0, B1, B2 -> Option D
  4. Quick Check:

    concatMap preserves order by waiting for each inner observable [OK]
Quick Trick: concatMap processes inner observables sequentially [OK]
Common Mistakes:
MISTAKES
  • Assuming emissions from inner observables interleave
  • Confusing concatMap with mergeMap behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes