Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to give Alert Controller css in ionic 4?

I want to give alert controller style in ionic 4.these is my demo code,

async presentalert() {
    const alert = await this.alertCtrl.create({
      header: '  DO YOU WANT TO CANCEL',
      message: 'DO YOU WANT TO CANCEL',
      cssClass: 'alertCancel',
      mode: 'ios',
      buttons: [
        {
          text: 'NO',
          role: 'cancel',
          cssClass: 'alertButton',
          handler: () => {
            console.log('Confirm Cancel');
          }
        }, {
          text: 'YES',
          cssClass: 'alertButton',
          handler: () => {
            console.log('Confirm Okay');
          }
        }
      ]
    })
    await alert.present();
  }

and i tried to apply scss in global.scss

 .alertCancel{
    --background: red;
  }
  .alertButton {
     background-color: white !important;
  }

I have tried every possible way to give css in alert controller but it s not working so please help me I am stuck here.

like image 281
Aniruddh Thakor Avatar asked Apr 15 '19 10:04

Aniruddh Thakor


People also ask

How do you show alerts in ionic?

In this typescript file, we need first to import the Alert Controller. Then, create a showAlert() function, which contains the alert options such as header, sub-header, message, and button. After that, we create an onDidDismiss() method to resume an interaction with the app.

What is AlertController?

The alert controller lets you provide a block for configuring your text fields prior to display. The alert controller maintains a reference to each text field so that you can access its value later. Important. The UIAlertController class is intended to be used as-is and doesn't support subclassing.

How do I dismiss an ion alert?

Note: The right most button (the last one in the array) is the main button. Optionally, a role property can be added to a button, such as cancel . If a cancel role is on one of the buttons, then if the alert is dismissed by tapping the backdrop, then it will fire the handler from the button with a cancel role.


1 Answers

--background is a css variable of the component ion-alert, therefore do the following in the variables.scss

ion-alert
{
 --background: red !important;
}

For reference:

https://ionicframework.com/docs/theming/css-variables#ionic-variables

like image 126
Peter Haddad Avatar answered Nov 03 '22 00:11

Peter Haddad