How do I setInterval with Ionic?

0

My problem is that I do not know how to do a setInterval on Ionic3. I put the following in the .ts of my page:

export class ClickerPage {

public dinero=0;
public produccion=1;

constructor(public navCtrl: NavController) {
  setInterval(function(){
    this.dinero+=this.produccion;
  }, 1000);
}
 ...

And in the view I used:

<ion-item>
  <ion-icon name="cash" item-start></ion-icon>
  Dinero:
  <ion-badge item-end>{{dinero}}</ion-badge>
</ion-item>

But it does not work, it just does not update, I do not know if it goes in the constructor like I did, or it goes somewhere else in the setInterval. Can you help me? Thanks!

    
asked by rafemo 22.04.2018 в 20:58
source

1 answer

0

For those interested, I have managed to solve the problem with the following:

constructor(public navCtrl: NavController) {
 this.dinero = setInterval(() => {
  this.sumarDinero();
 }, 1000);
}
    
answered by 22.04.2018 / 21:51
source