How to stop the timer in Angular?

Viewed 142

How to stop the timer?

All code with implementation is available on StackBlitz.

If you click on button 'Go', the timer will start. I want to pause or stop this time, but how?

Main function is:

startTimerForSingleTraining(timer2) {
  console.log('timer 2', timer2)
  // if(timer2 === 'finished') {
  //   this.countDownForSingleStartTraining.unsubscribe();
  // } 
  this.countDownForSingleStartTraining = timer(0, this.tick)
    .subscribe(() => ++timer2.timer); 
}
1 Answers

Unsubscribe from the Observable:

this.countDownForSingleStartTraining.unsubscribe()

Related