IONIC 2 - Reload from the app pages

0

I'm developing an app where it's almost all assembled from data from an API on an external server, fetching information from an Oracle from a client.

After login, I have in the HomePage the ngInit function that searches the data in this external API. When I navigate in other pages of the app and I go back to the HomePage, I have to keep searching the data again, because it seems that when leaving the HomePage the data loaded in the variables previously are empty.

Is there a smarter way to do this, that is, not be calling the API every time you enter HomePage?

    
asked by anonymous 17.08.2018 / 14:23

1 answer

0
getMetaLoja() {
this.idempresa = this.navParams.get('empresa'); 

var link = 'http://xxxxxxx.com/xxx/xxx/xxxxx.php';
var data = JSON.stringify({idEmpresa: this.idempresa});

this.http.post(link, data).subscribe(data => {
  this.data.response = data._body;
  this.metaloja = JSON.parse(<string>this.data.response);
  if(this.metaloja === "" || this.metaloja === null || this.metaloja.length === 0)
  {
    let alert = this.alertCtrl.create({
    title: 'A meta da sua loja não foi encontrada',
    message: 'Por favor, verifique sua conexão de internet ou entre em contato com a administração do App para mais informações',
    buttons: [
      {
        text: 'Ok',
        handler: () => {
        this.navCtrl.push(LoginPage);
      }
    }
    ]
    });
    alert.present();
  }       
  }, error => {
    console.log("Oooops!");
  });
}
    
19.08.2018 / 06:26