【发布时间】:2020-04-07 16:46:31
【问题描述】:
我正在尝试制作一个带有进度条的按钮,按钮下方的文本将告诉您还剩多少时间。我正在使用在 [0 ... 1] 之间取值的离子进度条。
public timeToClose = 5 * 1000;
...
const interval = this.timeToClose / 100;
timer(0, interval).pipe(
tap((v) => this.progress = v / 100),
map(i => this.timeToClose - i * interval),
take(100),
tap((timeLeft) => this.timeLeft = Math.floor(timeLeft / 1000) + 1),
finalize(() => this.closeModal()),
).subscribe();
但这看起来很糟糕。我怎样才能使它更好的代码?
【问题讨论】:
标签: ionic-framework rxjs