Countdown Timer in Angular 6

后端 未结 3 480
挽巷
挽巷 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:27

    ngx-countdown is a more matured solution. It provides all the formatting options as well as start/stop/pause/resume functions.

    Live demo here

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-31 15:43

    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.

    0 讨论(0)
提交回复
热议问题