December 2018
Intermediate to advanced
196 pages
4h 48m
English
At its core, a Subject acts much like a regular observable, but each subscription is hooked into the same source, like the publish/share example. Subjects also are observers and have next, error, and done methods to send data to all subscribers at once:
| | let mySubject = new Subject(); |
| | |
| | mySubject.subscribe(val => console.log('Subscription 1:', val)); |
| | mySubject.subscribe(val => console.log('Subscription 2:', val)); |
| | |
| | mySubject.next(42); |
| | |
| | /* |
| | Console output: |
| | Subscription 1: 42 |
| | Subscription 2: 42 |
| | */ |
Because subjects are observers, they can be passed directly into a subscribe call, and all the events from the original observable will be sent through the subject to its subscribers. ...
Read now
Unlock full access