Scenario:
You’re building a shared service that needs to hold the latest value of a user’s settings and broadcast it across multiple components.
Answer:
-
Subject: Multicast, emits only to subscribers at the time of emission. -
BehaviorSubject: Remembers the latest emitted value, emits it immediately to new subscribers. -
ReplaySubject: Remembers a specified number of past values and replays them to new subscribers. -
AsyncSubject: Emits only the last value upon completion.
Example:
No comments:
Post a Comment