TypeScript

by Rishabh Sharma

HTML

<div id="app"></div>

TypeScript

class Timer {
	interval: any;

  public startInterval() {
  	window.clearInterval(this.interval);
  	this.interval = window.setInterval(() => {
    	console.log('I was called!');
    }, 1000);
  }
  
  public stopInterval() {
  	let self = this;
  	// clearing interval after 5 seconds
    window.setTimeout(() => {
    	console.log('stopping the interval');
      console.log(self.interval);
      window.clearInterval(self.interval);
    }, 5000);
  }
}

let timer = new Timer();

timer.startInterval();
timer.stopInterval();