Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to do a timer angular

timeLeft: number = 60;
  interval;

startTimer() {
    this.interval = setInterval(() => {
      if(this.timeLeft > 0) {
        this.timeLeft--;
      } else {
        this.timeLeft = 60;
      }
    },1000)
  }

  pauseTimer() {
    clearInterval(this.interval);
  }

<button (click)='startTimer()'>Start Timer</button>
<button (click)='pauseTimer()'>Pause</button>

<p>{{timeLeft}} Seconds Left....</p>
Comment

timer in angular 8

timeLeft: number = 60;
  interval;

startTimer() {
    this.interval = setInterval(() => {
      if(this.timeLeft > 0) {
        this.timeLeft--;
      } else {
        this.timeLeft = 60;
      }
    },1000)
  }

  pauseTimer() {
    clearInterval(this.interval);
  }
    
<button (click)='startTimer()'>Start Timer</button>
<button (click)='pauseTimer()'>Pause</button>

<p>{{timeLeft}} Seconds Left....</p>
Comment

PREVIOUS NEXT
Code Example
Javascript :: usereducer example 
Javascript :: arraylist to json array 
Javascript :: useeffect dependency error 
Javascript :: promise.all vs promise.allsettled 
Javascript :: javascript separate string by character 
Javascript :: how to unselect input javascript 
Javascript :: Next js window is not defined solution 
Javascript :: javascript get call stack 
Javascript :: what is status 400 in react 
Javascript :: javascript convert to array 
Javascript :: javascript get all days of week 
Javascript :: fs.readfile 
Javascript :: npm run build npm ERR! Missing script: "build" for firebase 
Javascript :: replace jquery 
Javascript :: jquery hide select option 
Javascript :: Number of documents in Mongodb 
Javascript :: run a local instance of Kibana on docker and connect to elasticsearch 
Javascript :: php watermark facile 
Javascript :: filter repetition multidimensional array javascript 
Javascript :: firebase auth update current user 
Javascript :: add array to array js 
Javascript :: search an array with regex javascript filter 
Javascript :: json minecraft 
Javascript :: react pass parameters to other page 
Javascript :: how to get sum array in javascript 
Javascript :: javascript reverse 
Javascript :: debouncing javascript 
Javascript :: jquery validator add method 
Javascript :: ace editor set theme 
Javascript :: react native scrollbar position issue 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =