ionic 3 alert
To display an alert in Ionic 3, you can use the AlertController
module. Here's a code snippet that demonstrates how to create and display an alert:
import { AlertController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public alertController: AlertController) {}
presentAlert() {
const alert = this.alertController.create({
title: 'Alert',
subTitle: 'This is an Ionic alert.',
buttons: ['OK']
});
alert.present();
}
}
In the above example, we import the AlertController
module from ionic-angular
. Inside the HomePage
component, we inject the AlertController
into the constructor. The presentAlert
method is called to create and display the alert. The create
method is used to create the alert with a title, a sub-title, and an OK button. Finally, the present
method is called to display the alert on the screen.
Remember to import the necessary modules and include the AlertController
in the constructor of your component.