Created
January 10, 2024 10:13
-
-
Save mreis1/dbc2b0719b41710b2d8a15733fbe651e to your computer and use it in GitHub Desktop.
Angular (NG): Snippet to display a count down in seconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Time Left: {{countDownSecondsLeft}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @todo: Somewhere in your code, start the count down by doing: _countDownInit(() => { /* code to be executed on countdown complete */ }) | |
// region countdown | |
private readonly COUNT_DOWN_SECS = 3; | |
private _countDownId: any; | |
countDownSecondsLeft = this.COUNT_DOWN_SECS; | |
private _countDownClear() { | |
clearInterval(this._countDownId); | |
this._countDownId = null; | |
} | |
private _countDownInit(cb: () => void) { | |
this._countDownClear(); | |
this.countDownSecondsLeft = this.COUNT_DOWN_SECS; | |
this._countDownId = setInterval(() => cb(), 1000); | |
} | |
private _countDownTick() { | |
const v = --this.countDownSecondsLeft; | |
if (v === 0) { | |
this.confirm(); | |
} | |
} | |
// endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment