How to update a field in Ionic automatically?

Asked

Viewed 136 times

0

I’m having trouble generating coordinates on Ionic using geolocation. It only works if you press several times the button that calls the function, until the coordinates appear. So, I wanted to know how to make a part of the code call the function automatically, without me updating "manually"?

<ion-item>
          <ion-input type="text" [(ngModel)]="cad.longitude" value="{{long}}" (click)="local()" readonly>
          </ion-input>
</ion-item>

2 answers

1


You can create a function in the file . ts that calls the function local() x in x minutes. In the example below, I call every 3 minutes. This parameter you set in the setInterval.

constructor() {


  platform.ready().then(() => {      

  setInterval(() => {
    this.local(); //sua função
  },180000);  //tempo em milisegundos


});

}

  • It worked fine. Thank you!

1

var geolocationInterval;

ionViewDidLoad() {
    geolocationInterval = setInterval(() => this.local(), 5000);
}

ionViewWillLeave() {
    clearInterval(geolocationInterval);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.