按下AlertController的选项按钮离子时输入另一页

时间:2017-07-24 07:58:36

标签: angular typescript ionic-framework mobile-development

我有一个AlertController,在添加新笔记后弹出。它有两个选项:“新笔记”和“看笔记”。按“查看备注”时,应输入其他页面以查看备注列表。按“新笔记”时,它应该保留在此页面上以添加新笔记。那么,如何按alertCtrl选项按钮进入另一个页面?

现在我有:

  showConfirm() {
    let confirm = this.alertCtrl.create({
      title: 'What do you want to do else?',
      buttons: [
        {
          text: 'New note',
          handler: () => {
            console.log('New note');
          }
        },
        {
          text: 'See notes',
          handler: () => {
            console.log('See notes');
          }
        }
      ]
    });
    confirm.present();

enter image description here

2 个答案:

答案 0 :(得分:0)

  showConfirm() {
    let confirm = this.alertCtrl.create({
      title: 'Use this lightsaber?',
      message: 'Do you agree to use this lightsaber to do good across the intergalactic galaxy?',
      buttons: [
        {
          text: 'Disagree',
          handler: () => {
            console.log('Disagree clicked');
            this.seeNotes(NotesPage);            
          }
        },
        {
          text: 'Agree',
          handler: () => {
            console.log('Agree clicked');
          }
        }
      ]
    });
    confirm.present();
  }
  seeNotes(str:any){
    this.navCtrl.push(str);
  }

答案 1 :(得分:0)

handler:方法内调用NavControllerpush所需的页面。

请参阅以下内容:

constructor(private navCtrl: NavController, private alertCtrl: AlertController) {}

showConfirm() {
  let confirm = this.alertCtrl.create({
    title: 'What do you want to do else?',
    buttons: [
      {
        text: 'New note',
        handler: () => {
          this.navCtrl.push(NewNotesPage);
        }
      },
      {
        text: 'See notes',
        handler: () => {
          this.navCtrl.push(SeeNotesPage);
        }
      }
    ]
  });
  confirm.present();