小编mag*_*arm的帖子

如何使用 RxJS 和 Angular 制作 5 分钟倒计时器

倒计时应该从 4:59,4:58,....0:00 开始。我试过这个:

export class CounterComponent {
  @Input() since!: number
  readonly timeToShow$ = timer(0, 1000).pipe(
    map(() => Math.floor((Date.now() / 1000 - this.since) / 60)),
  )
}
Run Code Online (Sandbox Code Playgroud)
<span *ngIf="((timeToShow$ | async) || 0) > 0; else recentlyAdded">
    {{ timeToShow$ | async }} Minute{{ (timeToShow$ | async) === 1 ? '' : 's' }}
  </span>
Run Code Online (Sandbox Code Playgroud)

但这给了我从今天开始经过的时间。我只需要 5 分钟倒计时。

rxjs angular

1
推荐指数
1
解决办法
6887
查看次数

标签 统计

angular ×1

rxjs ×1