# Alert missing present

**URL:** <https://forum.ionicframework.com/t/alert-missing-present/148401>\
**Category:** Ionic Framework\
**Created:** [November 23, 2018, 2:13pm UTC](https://forum.ionicframework.com/t/alert-missing-present/148401 "2018-11-23T14:13:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulSinnema](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/paulsinnema/32/122872_2.png) [@PaulSinnema](https://forum.ionicframework.com/u/PaulSinnema)\
**Post date:** [November 23, 2018, 2:13pm UTC](https://forum.ionicframework.com/t/alert-missing-present/148401/1 "2018-11-23T14:13:33Z")

</div>

I’m in the process of learning new skills with Ionic 4 and Angular. I’m following a course on UDemy. In my first attempt to complete an assignment I could not get a simple example with AlertController to work. The code from UDemy looks like this (note: It’s a course from 2015 using Ionic 2):

showAlert()  
{  
let alert = this.alertController.create({  
message: “Joepie”,  
subHeader: “Test”  
});  
alert.present();  
}

I’m using Visual Studio Code and it immediately gives me an error on ‘present’. After struggling a while with the code I came up with the code below. It is working (with Ionic 4) but I’m a bit uncertain about it. Is this how it is supposed to work?

showAlert()  
{  
let alert = this.alertController.create({  
message: “Joepie”,  
subHeader: “Test”  
});  
alert.then(x =\> x.present());  
}

---

<div class="post-metadata">

**Author:** ![FdezRomero](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/fdezromero/32/110635_2.png) [@FdezRomero](https://forum.ionicframework.com/u/FdezRomero)\
**Post date:** [November 23, 2018, 3:34pm UTC](https://forum.ionicframework.com/t/alert-missing-present/148401/2 "2018-11-23T15:34:26Z")

</div>

Hi Paul!

Some things have changed in Ionic 4 since Ionic 2 😉 One of them being that when components get created with their controllers – like `alertController.create(...)` – they now return a promise containing the component instead of the component itself.

The code you wrote is correct, but you might find it easier to handle using async/await like this (the code is equivalent):

```auto
async showAlert() {
  const alert = await this.alertController.create({
    message: “Joepie”,
    subHeader: “Test”
  });

  await alert.present();
}

```

You can find the docs for Ionic 4 here: [https://beta.ionicframework.com/docs/api/alert](https://beta.ionicframework.com/docs/api/alert)

Best,  
Rodrigo

---

<div class="post-metadata">

**Author:** ![PaulSinnema](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/paulsinnema/32/122872_2.png) [@PaulSinnema](https://forum.ionicframework.com/u/PaulSinnema)\
**Post date:** [November 23, 2018, 3:54pm UTC](https://forum.ionicframework.com/t/alert-missing-present/148401/3 "2018-11-23T15:54:20Z")

</div>

Ah, await, looks like C# 😀 Yup, seems to work. Thanks for this.

---

<div class="post-metadata">

**Author:** ![FdezRomero](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/fdezromero/32/110635_2.png) [@FdezRomero](https://forum.ionicframework.com/u/FdezRomero)\
**Post date:** [November 23, 2018, 3:59pm UTC](https://forum.ionicframework.com/t/alert-missing-present/148401/4 "2018-11-23T15:59:39Z")

</div>

Yeap, it’s just modern Javascript (ES2017), but it’s easier to reason about promises and resolved values. I’m glad it helped!

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:08pm UTC](https://forum.ionicframework.com/t/alert-missing-present/148401/5 "2021-07-19T21:08:32Z")

</div>

Closed on July 19, 2021, 9:08pm UTC


