Vicheanak
Vicheanak

Reputation: 6684

Change message in Alert Popup - Ionic 2

I have this:

  doAlert() {
      let alert = this.alertCtrl.create({
           title: 'My Popup',
           message: this.updateStatus
      });
      alert.present()
  }

  this.updateStatus = 'Start';
  this.doAlert();

  setTimeout(() => {
      this.updateStatus = 'Finish';
      console.log('Done Timeout');
  }, 1000);

The alert shows only Start like picture below, even the console.log is trigger.

enter image description here

How can I trigger it to change the message to Finish?

Upvotes: 1

Views: 3309

Answers (2)

Klemens Zleptnig
Klemens Zleptnig

Reputation: 1824

Solution for Ionic 5 (will also work with Ionic 4) if anybody is stumbling over this:

this.loader = await this.loadingCtrl.create({
    message: 'Please wait ...'
});
this.loader.present();

Then at some point in the future, update the message like this:

this.loader.message = 'Still waiting? 🙄';

Upvotes: 1

LeRoy
LeRoy

Reputation: 4436

Apparently you can, I just tried it :). Its best if you use a loader(Alerts are normally for confirmation messages)

FYI: make sure your loader is global...

Add this in your class

loader: any;

Add this in your Constructor:

this.loader = loadingCtrl.create({
  content: "Logging in, Please wait..."
});
this.loader.dismissAll()

Then You can add this where you want your text to change

this.loader.data.content = "Still waiting ? LOL";

Upvotes: 5

Related Questions