@kismog wrote:
Hi all…
I have a bug that I can’t fix in two days
I have two components that has got one setInterval to call a function every x seconds.
I can’t understand why, but the first “setInterval” changes the one of the second component. In practice the second component starts at the same seconds as the “setInterval” of the first component.
A piece of the code of the two components:
First component *****************
export class SchermataInizialePage implements OnInit {
constructor(private qrCodeService:QrCodeService,private restApiService:RestApiService) {this.effettuaChiamataDisponibilitàPompa(); this.interv=setInterval(data=>{ this.effettuaChiamataDisponibilitàPompa(); },10000);}
ionViewWillLeave(){
if(this.interv=!null)
{
console.log(“this.interv è diverso da null”);
clearInterval(this.interv);
}
}Second component *********************
export class HomePage {
starts this function for a video Timer:
startTimerVisivo()
{console.log("startato timer visivo"); console.log("flagBottoneOn VALORE3: "+this.flagBottoneOn) this.minuti=14;this.secondi=59;
this.interval = setInterval(() => {
if(this.minuti==0 && (this.secondi)==0)
{
this.pauseTimer();
}
this.acquaConsumata=+this.acquaConsumata + +100;
this.acquaConsumataml=this.acquaConsumata+" ml";if(this.secondi>0) { if(this.secondi<10) { this.minutiESecondi=this.minuti+":0"+this.secondi; this.secondi--; } else{ this.minutiESecondi=this.minuti+":"+this.secondi; this.secondi--; } } else { this.minutiESecondi=this.minuti+":0"+this.secondi; this.secondi=59; this.minuti--; } },1000)}
}Please help me!
Thank you
Posts: 1
Participants: 1
