I am programming using Ionic 2, and I want to show a pop-up alert when a button is clicked.
This is the code in my home.html:
<button (click)='openFilters()'>CLICK</button>
And in my 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();
}
}
I have read some StackOverflow questions on this topic and tried to implement it like this:
openFilters() {
let alert:Alert = Alert.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
this.nav.present(alert);
}
Still, I accomplished nothing; I get errors.
Make sure to import this:
import {AlertController} from 'ionic-angular';
and have code such as this:
constructor(private alertController: AlertController) {
}
openFilters() {
let alert = this.alertController.create({
title: 'Example',
subTitle: 'Example subtitle',
buttons: ['OK']
});
alert.present();
}
Things have changed with Beta 11, and it seems as if the documentation online is not yet updated, you can always go into the ionic-angular folder in your node_modules and find the component that you are trying to use for examples of better documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With