在 Ionic 2 中使用弹出窗口

Use of Popups in Ionic 2

当我尝试在单击按钮后显示警告弹出窗口时出现以下错误:

EXCEPTION: TypeError: Cannot read property 'length' of undefined in [null] ORIGINAL EXCEPTION: TypeError: Cannot read property 'length' of undefined

这是我的代码:

popups.html:

<ion-content padding class="getting-started">

   <button primary (click)="showAlertPopup()">Alert</button>

</ion-content>

popups.js

import {Page, NavController, Popup} from 'ionic/ionic';

@Page({
  templateUrl: 'app/popups/popups.html'
})

export class PopupsPage {
  constructor(nav: NavController, popup: Popup) {
       this.nav = nav;
       this.popup = popup;
  }

  showAlertPopup(){
       this.popup.alert({
           title: 'Ionic Popup',
           template: 'This is alert popup'
       });
  }
}

有小费吗?

这是 Ionic2 版本的错误。更新到版本 alpha 37 后按预期工作。

对于那些在 >=2017 年访问此问题的人,您应该使用 AlertController

一个例子:

import { AlertController } from 'ionic-angular';

constructor(private alertCtrl: AlertController) {

}

presentAlert() {
    let alert = this.alertCtrl.create({
        title: 'Low battery',
        subTitle: '10% of battery remaining',
        buttons: ['Dismiss']
     });
     alert.present();
}

请参阅 official docs 了解更多示例,例如 ConfirmAlert、PromptAlert 等。