首页 文章

在Ionic3中从AlertController获取输入后,显示具有刷新页面的新警报

提问于
浏览
1

我正在使用alertPromt,我有一个输入字段 . 我有两个选项说'ok'和'next'和'cancel' .

如果用户点击“下一步”,我需要捕获输入值并添加到后面的列表中并再次显示一个新警报,要求在ionic3中提供更多来自用户的输入 .

这应该是一个持续的过程 .

Issue Facing: 目前,对于第一个实例,页面刷新并创建新警报 . 现在,如果我点击'next'按钮,警报将永远保留,我无法从视图中删除它 .

Solutions Tried: 我试图在调用新警报之前解除警报,但是这给了我一个错误说,删除了view()一些错误 . 问题仍然存在 .

我正在尝试在Android设备上运行此代码 . iOS设备我还没试过 .

警报我正在使用AlertController .

addNewItem(){
    this.showItemAddAlert();
  }

  showItemAddAlert(){
    let prompt = this.alertCtrl.create({
      cssClass: 'custom-alert',
      title: 'Title',
      message: "Enter a name of the item.",
      inputs: [
        {
          id : 'alertInputId',
          name: 'itemName',
          placeholder: 'Item Name',
          value: ""
        },
      ],
      buttons: [
        {
          cssClass : 'first-button',
          text: 'Next',
          handler: data => {
             if(data.itemName !=""){
              this.addNewItem();

             }else{
                console.log('log here');
             }

          }
        },
        {
          text: 'Cancel',
        },
        {
          text: 'Ok',
          handler: data => {
            if(data.itemName !=""){
              console.log('add input here');
            }

          }
        }
      ]
    });
    prompt.present()
  }

1 回答

  • 0

    这里我们有第一个提示,其中显示了初始警报,我有一个像 this.myNewPromt(data) 的功能,下一个带有输入数据 .

    如果你想要,你可以再次拨打presentPrompt,这将创建一个新的警报;

    presentPrompt() {
          const alert = this.alertCtrl.create({
            title: 'title',
            inputs: [
              {
                name: 'Add',
                placeholder: 'Title'
              }
            ],
            buttons: [
              {
                text: 'Cancel',
                role: 'cancel',
                handler: data => {
                  console.log('Cancel clicked');
                }
              },
              {
                text: 'OK',
                handler: data => {
    
                }
              },{
                text: 'Next',
                handler: data => {
                  this.myNewPromt(data);
                }
              }
    
            ]
          });
          alert.present();
        }
    
    
    
    myNewPromt(data){
       if(data){
         //do your stuff
         this.presentPrompt();//which creats an new promt 
       }else{
         //do your stuff
         //if you don't want then we are not calling if you want you can call.
       }
    }
    

相关问题