How to import rxjs timer in angular 6?

anonymous picture anonymous · May 8, 2018 · Viewed 21.8k times · Source

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

Answer

ashfaq.p picture ashfaq.p · May 8, 2018

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