Issue with Alert Not Showing on Click or Tap Event in Ionic 2: I am facing a problem where the function is not triggered when clicking a list item in Ionic. Since I am using native components, I can only test on the device which does not show any runtime errors.
I am uncertain of what is causing this issue, so any assistance would be highly appreciated. Below is the code snippet:
import { Component } from '@angular/core';
import { Hotspot, HotspotNetwork } from '@ionic-native/hotspot';
import { IonicPage, NavController, NavParams, AlertController } from
'ionic-angular';
@IonicPage()
@Component({
selector: 'page-wifilist',
templateUrl: 'wifilist.html',
})
export class WifilistPage {
networks: any;
wifiCredentials: {
ssid: string,
password: string
}
constructor(public hotspot: Hotspot, public navCtrl: NavController,
public alertCtrl: AlertController, public navParams: NavParams) {
}
ionViewDidLoad() {
this.hotspot.scanWifi().then((networks: Array<HotspotNetwork>) => {
this.networks = networks;
});
console.log('ionViewDidLoad WifilistPage');
}
setWifiCredentials(ssid: string) {
console.log('working');
this.wifiCredentials.ssid = ssid;
let passwordAlert = this.alertCtrl.create({
title: 'Wifi Credentials',
subTitle: 'Enter password for ' + this.wifiCredentials.ssid,
inputs: [
{
name: 'password',
placeholder: 'password',
type: 'password'
}
],
buttons: [
{
text: 'cancel',
role: 'cancel'
},
{
text: 'connect',
handler: data => {
this.wifiCredentials.password = data.password;
}
}
]
});
passwordAlert.present();
this.alertCtrl.create({
title: this.wifiCredentials.ssid + ' ' + this.wifiCredentials.password,
buttons: ['ok']
}).present();
}
}
And here is the HTML code:
<ion-header>
<ion-navbar>
<ion-title>
Wifi Scanner
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item *ngFor="let x of networks" (tap)='setWifiCredentials(x.SSID)'>
<ion-avatar item-start>
<img src="./assets/imgs/wifi-logo.png">
</ion-avatar >
<h1 (tap)='setWifiCredentials(x.SSID)'>{{x.SSID}}</h1>
</ion-item>
</ion-list>
</ion-content>