【问题标题】:Show a new alert with refreshing page after taking input from AlertController in Ionic3从 Ionic3 中的 AlertController 获取输入后,显示带有刷新页面的新警报
【发布时间】:2018-04-14 22:39:32
【问题描述】:

我在有输入字段的地方使用 alertPromt。我有两个选项说“确定”、“下一步”和“取消”。

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

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

问题面临:目前,对于第一个实例,页面刷新并创建新警报。现在,如果我单击“下一步”按钮,警报将永远保留,我无法将其从视图中删除。

已尝试的解决方案:我尝试在调用新警报之前关闭警报,但这给了我一个错误,说删除 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()
  }

【问题讨论】:

    标签: android angularjs typescript ionic2 ionic3


    【解决方案1】:

    在这里,我们首先提示显示初始警报的位置,我有一个类似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.
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多