I am currently working with Angular 5.
Is there a way to initiate a timer as soon as the 'play' button is clicked, in order to track the elapsed time since the click?
Additionally, I am interested in learning if it's feasible to pause the timer and then resume from where it was paused.
After some trial and error, I found a solution based on Pardeep Jain's response. Though it wasn't exactly what I had in mind. Instead of a countdown, I needed to track the duration. Below is the code snippet that resolved my issue:
time: number = 0;
interval;
startTimer() {
this.play = true;
this.interval = setInterval(() => {
this.time++;
},1000)
}
pauseTimer() {
this.play = false;
clearInterval(this.interval);
}