Solution - New Observable
Solution
import { Observable } from 'rxjs';
const o = new Observable((subscriber) => {
subscriber.next(1);
});
o.subscribe((value) => {
console.log(value);
});
See the solution on codesandbox
Let's review the solution code above:
- First, we import the
Observable
class from therxjs
dependency. - Next, we create a new instance of the
Observable
class. - We provide a callback function that is invoked with the
subscriber
. - We invoke the
next()
method on thesubscriber
, specifying the value of1
. - We invoke the
subscribe()
method on theObservable
instance and log out the value.