@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();
});
}
}```
This is what i wrote as of now it just continues as seconds and keeps counting, but i want it to count to minutes.
ok here are some changes ive done
@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();
});
}
}
i now can get 60 secs to 1:00 but after that it starts counting seconds again, i belive that i am missing something in the "if" statement
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.