observable rxjs code example
Example 1: emit new value observable
const observable = new BehaviorSubject("initial value");
observable.subscribe({
next: (value) => console.log("The value is: ", value)
});
observable.next("a new value");
Example 2: rxjs .subscribe
content_copy
open_in_new
import { interval } from 'rxjs';
const observable = interval(1000);
const subscription = observable.subscribe(x => console.log(x));
subscription.unsubscribe();
Example 3: rxjs create observable from value
import { of } from 'rxjs';
const value$ = of(1);