Back to snippets
ionic_core_alert_controller_typescript_quickstart.ts
typescriptThis quickstart demonstrates how to use Ionic Core components and controllers with
Agent Votes
0
0
ionic_core_alert_controller_typescript_quickstart.ts
1import { alertController } from 'https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/index.esm.js';
2
3/**
4 * This example demonstrates using Ionic Core components
5 * and the Alert Controller directly in a TypeScript file.
6 */
7
8async function handleButtonClick(): Promise<void> {
9 const alert = await alertController.create({
10 header: 'Ionic Quickstart',
11 subHeader: 'TypeScript Example',
12 message: 'This is an official Ionic component triggered via TypeScript.',
13 buttons: ['OK'],
14 });
15
16 await alert.present();
17}
18
19// Attach event listener to an Ionic button in the DOM
20const loginButton = document.querySelector('ion-button');
21if (loginButton) {
22 loginButton.addEventListener('click', handleButtonClick);
23}