November 2019
Beginner
804 pages
20h 1m
English
Subject (https://rxjs-dev.firebaseapp.com/guide/subject) is both Observable and Observer. As Observer, it watches over a data source (for example, a type of event or an external data source) and as Observable, it can be subscribed to, and therefore emit events or values to its subscribers (that is, observers).
Here is an example:
import { Subject } from 'rxjs'; const observer1 = { next: (value: string) => console.log(`Observer 1: ${value}`) }; const observer2 = { next: (value: string) => console.log(`Observer 1: ${value}`) }; const mySubject = new Subject<string>(); mySubject.subscribe(observer1); mySubject.subscribe(observer2); mySubject.next("Hello"); mySubject.next("World"); // Output: // Observer 1: Hello // Observer ...Read now
Unlock full access