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
Observableclass from therxjsdependency. - Next, we create a new instance of the
Observableclass. - 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 theObservableinstance and log out the value.