10 examples of 'timer in angular' in JavaScript

Every line of 'timer in angular' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
61private startTimer() {
62 this.el.classList.remove(`stopped`)
63 this.startTime = Date.now()
64 this.timerInterval = window.setInterval(() => {
65 const timeLeft = this.timeLeftMilliseconds()
66 if (timeLeft <= 0) {
67 this.stopTimer()
68 this.notifyCompletion()
69 } else {
70 this.displayTimeLeft(formattedTimeSeconds(timeLeft))
71 }
72 }, updateIntervalMs)
73}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

36private startTimer() {
37 this.el.classList.remove(`stopped`)
38 this.startTime = Date.now()
39 this.timerInterval = window.setInterval(() => {
40 const timeLeft = this.timeLeftMilliseconds()
41 if (timeLeft <= 0) {
42 this.stopTimer()
43 this.notifyCompletion()
44 } else {
45 this.displayTimeLeft(formattedTimeSeconds(timeLeft))
46 }
47 }, updateInterval)
48}
30private loseTime() {
31 this.lostTimeMs += penaltyMs
32 this.el.classList.add(`penalized`)
33 setTimeout(() => this.el.classList.remove(`penalized`), 200)
34}
139function startTimer(duration, display) {
140 var timer = duration, hours, minutes, seconds;
141 setInterval(function () {
142 if (timer > 0) {
143 hours = parseInt(timer / 3600, 10);
144 minutes = parseInt( (timer-(hours*3600))/60, 10);
145 seconds = parseInt(timer % 60, 10);
146 hours = hours < 10 ? hours : hours;
147 minutes = minutes < 10 ? "0" + minutes : minutes;
148 seconds = seconds < 10 ? "0" + seconds : seconds;
149
150 display.textContent = hours + ":" + minutes + ":" + seconds;
151 --timer;
152 } else {
153 hours = Math.abs(parseInt(timer / 3600, 10));
154 minutes = Math.abs(parseInt( (timer+(hours*3600))/60, 10));
155 seconds = Math.abs(parseInt(timer % 60, 10));
156 hours = hours < 10 ? hours : hours;
157 minutes = minutes < 10 ? "0" + minutes : minutes;
158 seconds = seconds < 10 ? "0" + seconds : seconds;
159
160 display.textContent = "- "+ hours + ":" + minutes + ":" + seconds;
161 display.className="message";
162 --timer;
163 }
164 }, 1000);
165}
84setSecondsTimer() {
85 this.secondsTimer = setInterval(() => {
86 setSeconds(getSeconds() - 1)
87 this.checkPoint()
88 }, 1000)
89}
7function onTimer() {
8
9 if($('#endgame')) $('#endgame').remove()
10
11 if (time === 20) {
12 if (level > 5) level = 1;
13 intervalId = setInterval(() => fallingPizza(level), ((3500 - (150*level))))
14 level += 1
15 }
16 $('#site').removeClass("hiddenClass");
17 $('#site').addClass("showClass");
18 $('#mycounter').show()
19 $('#start').hide()
20 document.getElementById('mycounter').innerHTML = time;
21 time--;
22
23 if (time < 0) {
24 $('#site').removeClass("showClass");
25 $('#site').addClass("hiddenClass");
26 document.getElementById('start').innerHTML = 'Start Game: Level ' + level;
27 $('#start').show()
28 $('#mycounter').hide()
29 $('#score').hide()
30 time = 20
31 clearInterval(intervalId)
32 endCheck(level)
33 }
34
35 else {
36 setTimeout(onTimer, 1000);
37 }
38}
173updateTimer () {
174
175 if ( this.intervalId ) clearInterval ( this.intervalId );
176
177 if ( !this.itemProps.visibility ) return;
178
179 this.intervalId = setInterval ( this.updateText.bind ( this ), 1000 );
180
181}
131(function timer() {
132 diff = that.duration - Math.floor((Date.now() - start) / 1000);
133
134 if (diff > 0) {
135 that.timeoutId = setTimeout(timer, that.granularity);
136 that.tick(diff);
137 } else {
138 that.running = false;
139 that.tick(0);
140 that.expire();
141 }
142}());
296function timer() {
297 firstClick = true;
298 counter = setInterval(function () {
299 seconds += 1;
300
301 second = (seconds % 60);
302 minute = parseInt(seconds / 60);
303
304 // if second < 10 add a 0 before the seconds
305 if (second < 10) {
306 second = `0${(seconds % 60)}`;
307 }
308
309 // if minutes < 10 add a 0 before the minutes
310 if (minute < 10) {
311 minute = `0${parseInt(seconds / 60)}`;
312 }
313
314 $('#time-info').html(`${minute} : ${second}`);
315
316 }, 1000);
317}
50startInterval() {
51 this.interval = window.setInterval(() => {
52 this.fetch(getUrl(this.props.match.params.runId))
53 }, interval)
54}

Related snippets