0

I would like to write an if statement within my alert controller for a button to change text based on the phone type (ios or android). Is this possible?

      title: `...`,
      subTitle: `...`,
      message: `<div class="image-container"> <img id='...' alt='...' />`,
            buttons: [ {
              cssClass: `cancel-button`,
              text: `X`,
            },
            {
              cssClass: `secure-hub`,
              text: `Go To Play Store`, \\<<<<<<<this text
            }
          ],
        });
    alert.present();
  • 1
    Here is your answer [https://stackoverflow.com/questions/21741841/detecting-ios-android-operating-system](https://stackoverflow.com/questions/21741841/detecting-ios-android-operating-system) – Jose Vicente Mar 01 '22 at 20:54

1 Answers1

1

In Ionic you can use Platform to determine what type of device the user is on.

Here an exemple of usage:

import { Platform } from '@ionic/angular';
import { AlertController } from '@ionic/angular';

@Component({...})
export class YourPage {
  constructor(
    public platform: Platform,
    public alertController: AlertController
   ) {}

  const yourFunction = () => {
     const alert = await this.alertController.create({
       header: `...`,
       subHeader​: `...`,
       message: `<div class="image-container"> <img id='...' alt='...' />`,
          buttons: [
          {
            cssClass: `cancel-button`,
            text: `X`,
          },
          {
            cssClass: `secure-hub`,
            text: this.platform.is('android') ? `Go To Play Store` : `Go to App Store`,
          }
        ],
     });

    alert.present();
  }
}
Kidoncio
  • 129
  • 3
  • 4