ရိုးရိုးလေး ရှင်းပြမယ်
Event Binding ( ) ကို ရိုးရိုးလေးနားလည်မယ်
Event Binding ( ) ကိုအသုံးပြုပြီး user actions (e.g., click , input ) များကို component ၏ method တစ်ခုနှင့် ချိတ်ဆက်နိုင်သည်။ Data သည် template မှ component သို့ one-way စီးဆင်းသည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Template မှာ `(click)` only သုံးထားတဲ့ non-button element က keyboard နှင့် assistive technology အသုံးပြုသူများအတွက်မရနိုင်ပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Event binding `(event)="handler($event)"` က DOM သို့ child output event ကို component behavior နဲ့ချိတ်ပါတယ်။ Handler က intent ကိုဖော်ပြပြီး validation/state transition ကိုလုပ်သင့်သော်လည်း template ထဲမှာ logic chain ကြီးမရေးသင့်ပါ။ Event type, bubbling, default behavior နဲ့ keyboard accessibility ကိုနားလည်ပြီး click-only interaction မဖြစ်စေရပါ။
- Input + state
- Component + template
- Rendered Angular UI
Event Binding ( ) ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
<button (click)="onSave()">Save</button>
<p>{{ message }}</p>
// component.ts
export class MyComponent {
message = '';
onSave() {
this.message = 'Data has been saved!';
}
}Event binding `(event)="handler($event)"` က DOM သို့ child output event ကို component behavior နဲ့ချိတ်ပါတယ်။ Handler က intent ကိုဖော်ပြပြီး validation/state transition ကိုလုပ်သင့်သော်လည်း template ထဲမှာ logic chain ကြီးမရေးသင့်ပါ။ Event type, bubbling, default behavior နဲ့ keyboard accessibility ကိုနားလည်ပြီး click-only interaction မဖြစ်စေရပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
<button (click)="onSave()">Save</button>Event Binding ( ) ကိုအသုံးပြုပြီး user actions (e.g., click , input ) များကို component ၏ method တစ်ခုနှင့် ချိတ်ဆက်နိုင်သည်။ Data သည် template မှ component သို့ one-way စီးဆင်းသည်။
- Component + template
message = '';Event binding `(event)="handler($event)"` က DOM သို့ child output event ကို component behavior နဲ့ချိတ်ပါတယ်။ Handler က intent ကိုဖော်ပြပြီး validation/state transition ကိုလုပ်သင့်သော်လည်း template ထဲမှာ logic chain ကြီးမရေးသင့်ပါ။ Event type, bubbling, default behavior နဲ့ keyboard accessibility ကိုနားလည်ပြီး click-only interaction မဖြစ်စေရပါ။
- Rendered Angular UI
}Submit button နဲ့ keyboard Enter နှစ်မျိုးမှ same save method ဆီဝင်အောင် form တစ်ခုရေးပြီး invalid input နဲ့ double submit ကိုကာကွယ်ပါ။
- Input + state
- Component + template
- Rendered Angular UI
Success
Event Binding ( ) ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
Template မှာ `(click)` only သုံးထားတဲ့ non-button element က keyboard နှင့် assistive technology အသုံးပြုသူများအတွက်မရနိုင်ပါ။
Event Binding ( ) ကိုအသုံးပြုပြီး user actions (e.g., click, input) များကို component ၏ method တစ်ခုနှင့် ချိတ်ဆက်နိုင်သည်။ Data သည် template မှ component သို့ one-way စီးဆင်းသည်။
<button (click)="onSave()">Save</button>
<p>{{ message }}</p>
// component.ts
export class MyComponent {
message = '';
onSave() {
this.message = 'Data has been saved!';
}
}(Button ကိုနှိပ်လိုက်လျှင် 'Data has been saved!' ဟူသော စာသား ပေါ်လာမည်)Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Submit button နဲ့ keyboard Enter နှစ်မျိုးမှ same save method ဆီဝင်အောင် form တစ်ခုရေးပြီး invalid input နဲ့ double submit ကိုကာကွယ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Event Binding ( ) နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<button (click)="onSave()">Save</button>
<p>{{ message }}</p>
// component.ts
export class MyComponent {
message = '';
onSave() {
this.message = 'Data has been saved!';
}
}ရလဒ်: Event Binding ( ) ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Submit button နဲ့ keyboard Enter နှစ်မျိုးမှ same save method ဆီဝင်အောင် form တစ်ခုရေးပြီး invalid input နဲ့ double submit ကိုကာကွယ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Input + state → Component + template → Rendered Angular UI
- Event binding `(event)="handler($event)"` က DOM သို့ child output event ကို component behavior နဲ့ချိတ်ပါတယ်။ Handler က intent ကိုဖော်ပြပြီး validation/state transition ကိုလုပ်သင့်သော်လည်း template ထဲမှာ logic chain ကြီးမရေးသင့်ပါ။ Event type, bubbling, default behavior နဲ့ keyboard accessibility ကိုနားလည်ပြီး click-only interaction မဖြစ်စေရပါ။
- Template မှာ `(click)` only သုံးထားတဲ့ non-button element က keyboard နှင့် assistive technology အသုံးပြုသူများအတွက်မရနိုင်ပါ။
- Submit button နဲ့ keyboard Enter နှစ်မျိုးမှ same save method ဆီဝင်အောင် form တစ်ခုရေးပြီး invalid input နဲ့ double submit ကိုကာကွယ်ပါ။
Angular — Templates — Angular