我想在我的警报控制器中写一个if语句,以便根据手机类型(ios或android)更改文本。这个是可能的吗?
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();发布于 2022-03-01 21:05:01
在Ionic中,您可以使用平台来确定用户所使用的设备类型。
这里是一个用法的例子:
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();
}
}https://stackoverflow.com/questions/71314490
复制相似问题