If you are stuck in pooling the request and need a timer just use these simple line of code.
poolOutTimer(poolTime: number) {
let timeLeft:number = poolTime;
var timerId = setInterval(countdown, 1000);
function countdown() {
if (timeLeft == 0) {
clearTimeout(timerId);
//do something here for stop..
console.log("Time UP : ");
} else {
//do something here while in progress..
console.log("Time Left : ", timeLeft);
timeLeft--;
if (timeLeft%5==0) {
console.log("Make New request here..");
} else {
console.log("Request Under Process..");
}
}
}
}
Just For typescript or if you are using ionic with dynamic loader, I created this to show message on loader
Here loading:any; is a variable declared for loader.
poolOutTimer(poolTime: number) {
this.timeLeft = poolTime;
this.timerId = setInterval(()=>this.countdown(), 1000);
this.showLoading();
}
countdown() {
if (this.timeLeft == 0) {
clearTimeout(this.timerId);
//do something here for stop..
console.log("Time UP : ");
this.loading.dismiss();
} else {
//do something here while in progress..
console.log("Time Left : ", this.timeLeft);
this.timeLeft--;
if (this.timeLeft%5==0) {
console.log("Make New request here..");
this.loading.setContent("New request");
} else {
console.log("Request Under Process..");
this.loading.setContent("Under Process");
}
}
}
showLoading() {
this.loading = this.loadingCtrl.create({
content: this.constant.loadingString
});
this.loading.present();
}
Author Profile
- Hey Its..! Tech Lover , Ionic, Angular, Typescript, Dotnet Core, Node, Like Opencv, AI, ML, Robotics, Iot, Love Music, Cooking, Girls, Innovation