Learn RxJS
Search…
Subject

A special type of Observable which shares a single execution path among observers

Examples

Example 1: simple Subject

1
// RxJS v6+
2
import { Subject } from 'rxjs';
3
4
const sub = new Subject();
5
6
sub.next(1);
7
sub.subscribe(x => {
8
console.log('Subscriber A', x);
9
});
10
sub.next(2); // OUTPUT => Subscriber A 2
11
sub.subscribe(x => {
12
console.log('Subscriber B', x);
13
});
14
sub.next(3); // OUTPUT => Subscriber A 3, Subscriber B 3 (logged from both subscribers)
Copied!

Additional Resources

Last modified 7mo ago