我Home.ts:Ionic 2/Angular 2:如何從超鏈接或按鈕上發出單擊事件Ionic 2 Alert?
import { Component } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,
public alertCtrl: AlertController) {
}
ShowAlert(){
let alert = this.alertCtrl.create({
title: '<b>Information</b>',
subTitle: `<a href="#" (click)="launchUrl('https://www.google.com')">Open Google</a>`,
buttons: ['Close']
});
alert.present();
}
launchUrl(url){
console.log(url);
}
}
我的HTML看起來像:
<button ion-button icon-only color="light" style="float: right" (click)="ShowAlert()">
Show Alert
</button>
而且我也得到了警報觸發成功。
現在當我點擊超鏈接:Open Google
時,沒有任何反應。我想通過單擊超鏈接調用launchUrl()
函數。
launchUrl(url){
console.log(url);
}
一旦我能夠調用launchUrl(),再後來我希望能修改如下所示使用科爾多瓦插件調用InAppBrowser。
launchUrl(url){
this.platform.ready().then(() => {
cordova.InAppBrowser.open(url, "_system", "location=true");
});
}
但是現在我甚至無法調用基本的launchUrl()
函數。 我試過(click)="launchUrl('https://www.google.com')"
和(click)="this.launchUrl('https://www.google.com')"
,但沒有成功。
請指教。
感謝您的迴應,但是我在Ionic 2的Alert文檔中找不到任何東西。我將在事件發射器上進行更多搜索,也許其他人可能會有一些解決方案。我認爲應該有一些從Ionic 2的警報中調用函數的方法。 –
或者我會嘗試使用Ionic 2的Modal。謝謝。 –
我添加了一個代碼,顯示Alert如何用於爲您完成這項工作。但是它不會創建出與上面相同的UI設計 – n00b