กดปุ่มแล้วมี Alert เด้งขึ้นมา
แก้ไขไฟล์ src/pages/home/home.html
โดยเพิ่มปุ่ม และเมื่อปุ่มถูกกดให้เรียกฟังก์ชัน doAlert()
1 2 3 4 5 6 7 8 9 10 11 |
<ion-header> <ion-navbar> <ion-title> Ionic Blank </ion-title> </ion-navbar> </ion-header> <ion-content padding> <button ion-button block color="dark" (click)="doAlert()">Show Basic Alert</button> </ion-content> |
แก้ไขไฟล์ src/pages/home/home.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { AlertController } from 'ionic-angular'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { constructor(public navCtrl: NavController, public alertCtrl: AlertController) { } doAlert() { let alert = this.alertCtrl.create({ title: 'New Friend!', message: 'Your friend, Obi wan Kenobi, just approved your friend request!', buttons: ['Ok'] }); alert.present() } } |