Ionic 4 alert

1.导入:

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

2.在沟槽函数里面声明:

constructor(public alertController: AlertController) {}

3.添加几个点击按纽:

<ion-button (click)="presentAlert()">
支付
</ion-button>
<ion-button (click)="presentAlertMultipleButtons()">
删除
</ion-button>

<ion-button (click)="presentAlertPrompt()">
添加信息
</ion-button>

4.点击事件里面写代码:

async presentAlert() {
const alert = await this.alertController.create({
   header: '提示信息',
   message: '支付成功',
   buttons: ['OK']
});
await alert.present();
}
async presentAlertMultipleButtons() {
    const alert = await this.alertController.create({
    header: '提示信息!',
    message: '您确定要删除吗',
    buttons: [
{
    text: '取消',
    role: 'cancel',
    cssClass: 'secondary',
    handler: (blah) => {
    console.log('Confirm Cancel: blah');
}
}, {
    text: '确定',
    handler: () => {
    console.log('Confirm Okay');
    }
    }
]
});
    await alert.present();
}

  async presentAlertPrompt() {
const alert = await this.alertController.create({
  header: '请输入信息',
  inputs: [
{
  name: '姓名',
  type: 'text',
  placeholder: '请输入姓名'
},
{
  name: '卡号',
  type: 'text',
  id: 'name2-id',
  value: 'hello',
  placeholder: '请输入卡号'
},
{
  name: '密码',
  type: 'url',
  placeholder: '请输入密码'
},
// input date with min & max
{
  name: '出生日期',
  type: 'date',
  min: '1900-03-01',
  max: '2019-08-25'
},
// input date without min nor max
{
  name: '年龄',
  type: 'number',
  min: 0,
  max: 109,
  placeholder: '请输入年龄'
},
{
  name: '手机号',
  type: 'number',
  placeholder: '请输入手机号'
}
],
buttons: [
{
  text: '取消',
  role: 'cancel',
  cssClass: 'secondary',
  handler: () => {
 console.log('Confirm Cancel');
}
}, {
  text: '确定',
  handler: () => {
  console.log('Confirm Ok');
  }
  }
]
});
   await alert.present();
}

 

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值