I need to execute a function when the timer reaches 0. Upon clicking a card, a popup appears and the countdown begins. Here is my current code:
openModal() {
switch (area) {
case 'a':
var self_t = this;
uid = 11;
let timer = 20;
let interval = setInterval(function () {
let elementID = document.getElementById('float-div');
if(elementID == null) {
timer = this.inSeconds;
}
if(timer >= 0) {
if(elementID) {
elementID.innerHTML = String(timer);
}
}
if (--timer == 0) {
if(elementID) {
elementID.innerHTML = '0';
}
if(area == "a") {
self_t.callFunction(uid); // debugger shows it not reaching here
clearInterval(interval);
}
}
}, 1000);
break;
case 'b':
console.log('something else');
break;
}
}
callFunction(uid) {
console.log(uid);
}
already attempted: using var self=this
If I use this.callFunction(uid)
, then it results in an error.