im creating a timer, and need your help im just learning angular & rxJS and i have some question about this
Im creating a timer which have start,stop,pause,reset
I create an timer with stop resume and pause https://stackblitz.com/edit/angular-gq9zvk.
Your variables
isstop = new Subject();
ispause = new Subject();
private time = 0;
isRunning = true;
timer: Observable<number>;
timerObserver: PartialObserver<number>;
This set timer put in in onInit or connect to click start function
this.timer = interval(1000)
.pipe(
takeUntil(this.ispause),
takeUntil(this.isstop)
);
this.timerObserver = {
next: (_: number) => {
this.time += 1;
}
};
this.timer.subscribe(this.timerObserver);
and these are stop resume and pause functions
goOn() {
this.isRunning = true;
this.timer.subscribe(this.timerObserver);
}
pauseClick() {
this.ispause.next();
this.isRunning = false;
}
stopClick() {
this.time = 0;
this.isRunning = false;
this.isstop.next();
}