我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