Countdown Timer in Angular 6

后端 未结 3 505
挽巷
挽巷 2020-12-31 15:21

Hi I am trying to get an example of a countdown timer I found searching on Stack found here: Time CountDown in angular 2

This is my code:



        
3条回答
  •  没有蜡笔的小新
    2020-12-31 15:35

    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

提交回复
热议问题