Asynchronous angular responses 4

1

I am making a request, and I am expecting a return, however it is asynchronous, it may take time or not, in my case I just want to display a message on the screen.

Hours it sends undefined and hours returns me the correct message.

Do I need to make sure this message exists how to do this?

this.loginprovider.validaLogin(user).subscribe(data => this.response = data);
if(!this.response.sucesso){
  this.showAlert("ERROR!",this.response.mensagem);
}

How to have this contest?

One detail:

I'm developing a hybrid app using the latest version of ionic (ionic 3) and angular (angle 4);

    
asked by anonymous 16.06.2017 / 16:32

1 answer

3

Just put the treatment inside the return:

this.loginprovider.validaLogin(user).subscribe(data => {
    this.response = data;
    if(!this.response.sucesso){
      this.showAlert("ERROR!",this.response.mensagem);
    }
});
    
16.06.2017 / 16:35