กดที่ปุ่ม Default จะแสดง Alert
กดที่ปุ่ม Toggle จะทำการ Enable/Disalbe ปุ่ม Default
src/pages/home/home.html
1 2 3 4 5 6 7 8 9 10 11 12 |
<ion-header> <ion-navbar> <ion-title> Ionic Blank </ion-title> </ion-navbar> </ion-header> <ion-content padding> <button ion-button (click)="showAlert()" [disabled]="!isenabled">Default</button> <button ion-button (click)="toggle()" color="danger">Toggle</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 |
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { isenabled: boolean = true; constructor(public navCtrl: NavController) { } showAlert() { alert("Default Button"); } toggle() { this.isenabled = !this.isenabled; } } |
บรรทัดที่ 10 : ตัวแปร isenabled
ใช้เก็บค่า Enable/Disalbe ให้ปุ่ม Default
Link