我使用Ionic 2進行編程,並且我想在單擊按鈕時顯示彈出警報。Ionic 2,如何正確使用警報
這是代碼在我home.html的:
<button (click)='openFilters()'>CLICK</button>
在我home.ts
import {Component} from '@angular/core';
import {Page, NavController, Alert} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
constructor(nav: NavController, alertCtrl: AlertController) {
}
openFilters() {
let alert = this.alertCtrl.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
alert.present();
}
}
我讀過一些關於這個論題計算器的問題,並試圖像這樣執行它:
openFilters() {
let alert:Alert = Alert.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
this.nav.present(alert);
}
我依然沒有任何表現;我收到錯誤。
您的項目中使用了哪種版本的Ionic?你可以通過在項目文件夾中執行'ionic info'來檢查,並且會說'Ionic Framework Version'。我問這個問題的原因,是因爲'Alerts'的創建方式已從版本'beta.10'改爲'beta.11'。 – sebaferreras
你或許應該告訴你得到了什麼錯誤 – YakovL
我離子信息: Cordove CLI:6.3.0 離子Framework版本:2.0.0-beta.11 離子CLI版本:2.0.0-beta.37 離子應用程序庫版本:2.0.0-beta.20 操作系統:Windows 7 SP1 節點版本:v4.4.7 –