gpt4 book ai didi

javascript - Angular 8 中 60 秒过去后如何将秒转换为分钟?

转载 作者:行者123 更新时间:2023-11-28 03:20:34 25 4
gpt4 key购买 nike

  @Input() maxSeconds = 60;
@Input() startSeconds = 0;
@Output() alarmSnooze: EventEmitter<number> = new EventEmitter<number>();
seconds: number;
private everySecond$: Observable<number> = timer(0, 1000);
private stopTimer$: Subject<{}> = new Subject();
private alarms: Array<number>;
constructor(private ref: ChangeDetectorRef) {
this.alarms = [29, 59];
}

ngOnInit() {
this.everySecond$.pipe(takeUntil(this.stopTimer$))
.subscribe((seconds) => {
this.seconds = (this.startSeconds + seconds);
if (this.alarms.includes(this.seconds)) {
this.alarmSnooze.emit(this.seconds);
}
this.ref.markForCheck();
});
}
}```

这是我现在写的内容,它只是以秒为单位继续并不断计数,但我希望它以分钟为单位。

最佳答案

好的,这是我所做的一些更改

  @Input() startSeconds = 0;
minutes = 0;
@Input() secs = this.startSeconds - this.minutes * 60;
// @Output() alarmSnooze: EventEmitter<number> = new EventEmitter<number>();
seconds: number;

private everySecond$: Observable<number> = timer(0, 1000);
private stopTimer$: Subject<{}> = new Subject();
private alarms: Array<number>;
constructor(private ref: ChangeDetectorRef) {
this.alarms = [29, 59];
}

ngOnInit() {
this.everySecond$.pipe(takeUntil(this.stopTimer$))
.subscribe((seconds) => {
this.seconds = seconds;
// if (this.alarms.includes(this.seconds)) {
// this.alarmSnooze.emit(this.seconds);
// }
if (this.seconds === 10){
this.seconds = 0;
this.minutes++;
}
this.ref.markForCheck();
});
}
}

我现在可以得到 60 秒到 1:00,但之后它又开始计时,我相信我在“if”语句中遗漏了一些东西

关于javascript - Angular 8 中 60 秒过去后如何将秒转换为分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59200099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com