首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于android或IOS更改警报按钮文本

基于android或IOS更改警报按钮文本
EN

Stack Overflow用户
提问于 2022-03-01 20:48:50
回答 1查看 90关注 0票数 0

我想在我的警报控制器中写一个if语句,以便根据手机类型(ios或android)更改文本。这个是可能的吗?

代码语言:javascript
复制
      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();
EN

回答 1

Stack Overflow用户

发布于 2022-03-01 21:05:01

在Ionic中,您可以使用平台来确定用户所使用的设备类型。

这里是一个用法的例子:

代码语言:javascript
复制
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();
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71314490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档