Complete the code to create a BehaviorSubject with initial value 0.
import { BehaviorSubject } from 'rxjs'; const count$ = new BehaviorSubject([1]);
The BehaviorSubject needs an initial value. Here, 0 is the starting number.
Complete the code to subscribe and log the current value from the BehaviorSubject.
count$.[1](value => console.log(value));To get updates from a BehaviorSubject, use subscribe.
Fix the error in updating the BehaviorSubject's value.
count$.[1](count$.value + 1);
To update a BehaviorSubject's value, use the next method.
Fill both blanks to create a simple store with BehaviorSubject and expose it as an observable.
private countSubject = new BehaviorSubject([1]); public count$ = this.countSubject.[2]();
The store starts with 0 and exposes the observable using asObservable() to prevent external updates.
Fill all three blanks to implement an increment method that updates the BehaviorSubject's value.
increment() {
const current = this.countSubject.[1];
this.countSubject.[2](current [3] 1);
}Get the current value with value, then call next with current plus one.
