How to update a field in ionic automatically?

0

I'm having trouble generating the coordinates in ionic using geolocation . It only works if you press and hold the button that calls the function until the coordinates appear. So I wanted to know how I can get a part of the code to automatically call the function, without me updating "manually"?

<ion-item>
          <ion-input type="text" [(ngModel)]="cad.longitude" value="{{long}}" (click)="local()" readonly>
          </ion-input>
</ion-item>
    
asked by anonymous 22.08.2018 / 16:27

2 answers

1

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

constructor() {


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

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


});

}

    
22.08.2018 / 16:40
1
var geolocationInterval;

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

ionViewWillLeave() {
    clearInterval(geolocationInterval);
}
    
22.08.2018 / 16:41