Angular 警报控制器设置消息在ionic 4中不工作

Angular 警报控制器设置消息在ionic 4中不工作,angular,ionic4,Angular,Ionic4,在alertController中,如果输入字段为空,我想调用prompt.setMessage()。但这在ionic4中不是有效的函数 代码 如果文本为空,我不想关闭警报提示 请提供帮助。您不再拥有Ionic 4中的方法,但您仍然可以直接更改message属性以实现所需: const prompt= await this.alertController.create({ header: 'insert text', message: 'enter text',

在alertController中,如果输入字段为空,我想调用prompt.setMessage()。但这在ionic4中不是有效的函数

代码

如果文本为空,我不想关闭警报提示
请提供帮助。

您不再拥有Ionic 4中的方法,但您仍然可以直接更改message属性以实现所需:

const prompt= await this.alertController.create({
      header: 'insert text',
      message: 'enter text',
      inputs: [
        {
          name: 'itemtext',
          placeholder: 'enter text'
        }
      ],
      buttons: [{
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Ok',
          handler: (data:any) => {
            if(data.itemtext==""){
              prompt.message = "text should not be empty";
              return false;
            }
            else{
              console.log(data.itemtext);
            }
          }
        }
      ]
    });
    await prompt.present();

我也从处理程序中的方法中删除了“asyc”,因为你不需要它。

我不确定这是不是可能的,但是如果结果不是,那么考虑使用一个模态,而不是让你完全控制加载并能够建立验证的页面。这个解决方案在FEB 2020中起作用。谢谢分享!
const prompt= await this.alertController.create({
      header: 'insert text',
      message: 'enter text',
      inputs: [
        {
          name: 'itemtext',
          placeholder: 'enter text'
        }
      ],
      buttons: [{
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Ok',
          handler: (data:any) => {
            if(data.itemtext==""){
              prompt.message = "text should not be empty";
              return false;
            }
            else{
              console.log(data.itemtext);
            }
          }
        }
      ]
    });
    await prompt.present();