import { interval } from 'rxjs'; const observable = interval(1000); // emits an integer every second observable.subscribe(value => console.log(value)); // logs each emitted value
import { interval } from 'rxjs'; import { take } from 'rxjs/operators'; const observable = interval(1000).pipe(take(5)); // emits 5 integers at 1 second intervals observable.subscribe(value => console.log(value)); // logs each emitted valueIn this example, we use the interval operator to create an observable that emits an integer every second. We then use the pipe operator to limit the observable to emit only 5 values. The take operator completes the observable after emitting five values. Finally, we subscribe to the observable and log each emitted value to the console. Overall, the rxjs.rx Observable interval is a convenient tool for working with time-based events and is a core package of the RxJS library.