How to import rxjs timer in angular 6?

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

  • https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#observable-classes

as of rxjs 6.2.2, for this import

import { timer } from 'rxjs';   // gives tslint blacklisted error

tslint gives an error:

ERR: [tslint] This import is blacklisted, 
import a submodule instead (import-blacklist)

but this works fine without any error

import { timer } from 'rxjs/observable/timer'; //works fine