IONIC 2 - App page reload

Asked

Viewed 58 times

0

I’m developing an app where it’s almost all assembled from data from an API on an external server, searching for information on an Oracle client.

After logging in, I have on the Homepage the function ngInit that searches the data in this external API. When I browse other pages of the app and go back to the Homepage, I have to look for the data again, because apparently, when leaving the Homepage the data loaded in the variables previously are empty.

There is a smarter way to do this, IE, don’t keep calling every time the API when entering the Homepage?

  • you are using providers to consume API data?

  • I’m not Felipe.... I’m wearing it like this:

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!");
  });
}
  • Junior search for Providers use Ionic generate Store command;

  • I’ll search Felipe, you can leave. Thank you!

Browser other questions tagged

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