How to show Timer


#1

Hi
I want to show a timer (Time remain) in my apps. I tried hard but did not find any solution. Can anybody help me plz


#2

Declare time remaining before constructor:

public timeLeft: number = 60;

Put this in your constructor:

var timer = setInterval(() => {
  if(this.timeLeft != 0) {
    this.timeLeft -=  1;
  } else {
    clearInterval(timer);
  }
 }, 1000);

Put this in your .html file:
<p>Time Remaining: {{ timeLeft }}</p>

I am sure there are more precise ways of doing this and more than likely simpler ways aswell but this should get you going.