the alerts are not working
DamianoP opened this issue · 1 comments
DamianoP commented
I have enabled the ion-alerts in the ionic.ts file, then if I try the following code the alerts are not showing up, they are only loaded into the dom.
async function presentAlert(header="Alert",subheader="Important message",message="This is an alert",buttonSTR="OK") {
const alert = document.createElement('ion-alert');
alert.header = header;
alert.subHeader = subheader;
alert.message = message;
alert.buttons = [buttonSTR];
document.body.appendChild(alert);
await alert.present();
const { role } = await alert.onDidDismiss();
console.log('onDidDismiss resolved with role', role);
}
If I import IONIC using the following syntax the alerts works normally
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
supertorpe commented
Hi! I've just commited a change with a working alert example: ecb7973.
Use an alertController to show the alert and that's it.
import { alertController } from '@ionic/core';
async function showAlert(header: string, subheader: string, message: string, buttons: string[]) {
const alert = await alertController.create({
header: header,
subHeader: subheader,
message: message,
buttons: buttons
});
alert.present();
}