Alert won't show up


#1

Hi
I have an alert function which I use a lot and it’s perfectly working , however there is only one case where it doesn’t show up , I don’t know why , here is the case :

 fileTransfer.upload(filepath,url , options, true).then(function(){
        console.log('tested');
        this.showAlert('succeeded','the photo was uploaded');
      });

and here is the function :

  showAlert(title1: string, message: string) {
    let alert = this.alertCtrl.create({
      title: title1,
      subTitle: message,
      buttons: ['ok']
    });
    alert.present();
  }

it’s been two days and I’m still confused !


#2

hey :slight_smile:
you are in the wrong context. in your case this. is the then functions context
use an arrow function:

fileTransfer.upload(filepath,url , options, true).then(() =>{
  console.log('tested');
  this.showAlert('succeeded','the photo was uploaded');
});

#3

that solved my problem !
thanks!!