Countdown Timer in Angular 6

From Rxjs 6.0 you have to import interval from rxjs/observable/interval.

And you have to use pipe operator to execute infinite number of operator sequentially.

import { interval } from 'rxjs';
import { map } from 'rxjs/operators'

this.$counter = interval(1000).pipe(
   map((x) => {
      this.diff = Math.floor((this.future.getTime() - new Date().getTime()) / 1000);
      return x;
  });
)


Reference: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md#build-your-own-operators-easily


Simply write:

import { interval } from 'rxjs';
import { map } from 'rxjs/operators'

interval(1000).pipe(
  map((x) => { /* your code here */ })
);

In RxJS 6+ there's no Observable.interval function.

Tags:

Angular

Rxjs