angular6 - 如何使用 Angular 7 创建 2 分钟倒数计时器?
问题描述
我不会创建 2 分钟倒数计时器。我也尝试了这段代码,但它是秒任何人请告诉我如何使用创建 2 分钟倒计时计时器angular 7 (typescript)
timer() {
this.countdown().subscribe(
t => {
this.value1 = t
},
null,
() => {
}
);
this.start(60);
}
// 60 秒计数代码
countdown(): Observable<number> {
return this._countdown.asObservable();
}
private isCounting = false;
start(count: number): void {
if (!this.isCounting) {
this.isCounting = true;
timer(0, 1000).pipe(
takeWhile(t => t < count),
map(t => count - t)
).subscribe(
t => this._countdown.next(t),
null,
() => {
this._countdown.complete();
this.isCounting = false;
this._countdown = new Subject<number>();
}
);
}
}