Complete the code to create a simple Subject in Angular.
import { [1] } from 'rxjs'; const subject = new [1]();
The Subject class is imported from 'rxjs' and instantiated to create a new Subject.
Complete the code to create a BehaviorSubject with an initial value of 0.
import { BehaviorSubject } from 'rxjs'; const behaviorSubject = new BehaviorSubject([1]);
A BehaviorSubject requires an initial value. Here, 0 is used as the starting value.
Fix the error in the code to create a ReplaySubject that buffers the last 3 values.
import { ReplaySubject } from 'rxjs'; const replaySubject = new ReplaySubject([1]);
The ReplaySubject constructor takes a number indicating how many previous values to buffer. It must be a number, here 3.
Fill both blanks to subscribe to a Subject and log emitted values.
subject.[1](value => { console.[2](value); });
Use subscribe to listen to Subject emissions, and console.log to print values.
Fill all three blanks to create a BehaviorSubject, emit a value, and subscribe to log it.
const behaviorSubject = new [1](0); behaviorSubject.[2](5); behaviorSubject.[3](value => console.log(value));
Create a BehaviorSubject with initial 0, emit a new value with next, and listen with subscribe.