Angular asynchronous responses 4

Asked

Viewed 212 times

1

I’m making a request, and I’m waiting for a return, however it is asynchronous, may or may not, in my case I just want to display a message on the screen.

Time she send undefined and hours returns me the correct message.

I need to make sure that 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 certainty ?

A detail:

I’m developing a hybrid app using the latest version of Ionic (Ionic 3) and angular (angular 4);

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);
    }
});

Browser other questions tagged

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