I tried importing rxjs timer on my angular 6 project like
import { timer } from 'rxjs/observable/timer';
I also tried it like,
Rx.Observable.timer(200, 100)
They don't work
Here is the code on plunker
RxJS' of() is a creational operator that allows you to create an RxJS Observable from a sequence of values. According to the official docs: of() converts the arguments to an observable sequence. In Angular, you can use the of() operator to implement many use cases.
RxJS (Reactive Extensions for JavaScript) is a library for reactive programming using observables that makes it easier to compose asynchronous or callback-based code.
The RxJS library is great for handling async tasks. It has a large collection of operators in filtering, error handling, conditional, creation, multicasting, and more. It is supported by JavaScript and TypeScript, and it works well with Angular.
From rxjs 6 (as used in angular 6 project), The general rule is as follows:
rxjs: Creation methods, types, schedulers and utilities
import { timer, Observable, Subject, asapScheduler, pipe, of, from,
interval, merge, fromEvent } from 'rxjs';
rxjs/operators: All pipeable operators:
import { map, filter, scan } from 'rxjs/operators';
Here is the migration guide: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#observable-classes
All observable classes (https://github.com/ReactiveX/rxjs/tree/5.5.8/src/observable) have been removed from v6, in favor of existing or new operators that perform the same operations as the class methods.
import { timer } from 'rxjs';
import { timeInterval, pluck, take} from 'rxjs/operators';
var sourcef = timer(200, 100)
.pipe(
timeInterval(),
pluck('interval'),
take(3)
)
Forked Example
See also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With