ရိုးရိုးလေး ရှင်းပြမယ်
Property Binding [ ] ကို ရိုးရိုးလေးနားလည်မယ်
Property Binding [ ] ကိုအသုံးပြုပြီး HTML element ၏ property တစ်ခု (e.g., src , disabled ) ကို component ၏ data နှင့် ချိတ်ဆက်နိုင်သည်။ Data သည် component မှ template သို့ one-wayစီးဆင်းသည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
`disabled="false"` ကို false property လို့ယူဆခြင်းမှားပါတယ်—attribute ရှိနေသရွေ့ disabled ဖြစ်နိုင်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Property binding `[target]="expression"` က string attribute မဟုတ်ဘဲ DOM/component/directive property ဆီ typed value ပို့ပါတယ်။ Attribute က initial markup metadata ဖြစ်သော်လည်း property က live runtime state ဖြစ်လို့ disabled, value, class စသည်တို့မှာကွာခြားချက်အရေးကြီးပါတယ်။ Child input binding တွင် parent က data owner ဖြစ်ပြီး object mutation policy ကိုတိတိကျကျထားရပါတယ်။
- Input + state
- Component + template
- Rendered Angular UI
Property Binding [ ] ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
<img [src]="imageUrl">
<button [disabled]="isButtonDisabled">Click Me</button>
// component.ts
export class MyComponent {
imageUrl = 'path/to/image.jpg';
isButtonDisabled = true;
}Property binding `[target]="expression"` က string attribute မဟုတ်ဘဲ DOM/component/directive property ဆီ typed value ပို့ပါတယ်။ Attribute က initial markup metadata ဖြစ်သော်လည်း property က live runtime state ဖြစ်လို့ disabled, value, class စသည်တို့မှာကွာခြားချက်အရေးကြီးပါတယ်။ Child input binding တွင် parent က data owner ဖြစ်ပြီး object mutation policy ကိုတိတိကျကျထားရပါတယ်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
<img [src]="imageUrl">Property Binding [ ] ကိုအသုံးပြုပြီး HTML element ၏ property တစ်ခု (e.g., src , disabled ) ကို component ၏ data နှင့် ချိတ်ဆက်နိုင်သည်။ Data သည် component မှ template သို့ one-wayစီးဆင်းသည်။
- Component + template
export class MyComponent {Property binding `[target]="expression"` က string attribute မဟုတ်ဘဲ DOM/component/directive property ဆီ typed value ပို့ပါတယ်။ Attribute က initial markup metadata ဖြစ်သော်လည်း property က live runtime state ဖြစ်လို့ disabled, value, class စသည်တို့မှာကွာခြားချက်အရေးကြီးပါတယ်။ Child input binding တွင် parent က data owner ဖြစ်ပြီး object mutation policy ကိုတိတိကျကျထားရပါတယ်။
- Rendered Angular UI
}Button disabled state, image source နဲ့ child object input သုံးမျိုး bind လုပ်ပြီး boolean/object က string မဖြစ်ဘဲပို့ကြောင်းစစ်ပါ။
- Input + state
- Component + template
- Rendered Angular UI
Success
Property Binding [ ] ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
`disabled="false"` ကို false property လို့ယူဆခြင်းမှားပါတယ်—attribute ရှိနေသရွေ့ disabled ဖြစ်နိုင်ပါတယ်။
Property Binding [ ] ကိုအသုံးပြုပြီး HTML element ၏ property တစ်ခု (e.g., src, disabled) ကို component ၏ data နှင့် ချိတ်ဆက်နိုင်သည်။ Data သည် component မှ template သို့ one-wayစီးဆင်းသည်။
<img [src]="imageUrl">
<button [disabled]="isButtonDisabled">Click Me</button>
// component.ts
export class MyComponent {
imageUrl = 'path/to/image.jpg';
isButtonDisabled = true;
}(Image တစ်ခုပေါ်လာပြီး button မှာ disabled (နှိပ်မရ) ဖြစ်နေမည်)Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Button disabled state, image source နဲ့ child object input သုံးမျိုး bind လုပ်ပြီး boolean/object က string မဖြစ်ဘဲပို့ကြောင်းစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Property Binding [ ] နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<img [src]="imageUrl">
<button [disabled]="isButtonDisabled">Click Me</button>
// component.ts
export class MyComponent {
imageUrl = 'path/to/image.jpg';
isButtonDisabled = true;
}ရလဒ်: Property Binding [ ] ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Button disabled state, image source နဲ့ child object input သုံးမျိုး bind လုပ်ပြီး boolean/object က string မဖြစ်ဘဲပို့ကြောင်းစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Input + state → Component + template → Rendered Angular UI
- Property binding `[target]="expression"` က string attribute မဟုတ်ဘဲ DOM/component/directive property ဆီ typed value ပို့ပါတယ်။ Attribute က initial markup metadata ဖြစ်သော်လည်း property က live runtime state ဖြစ်လို့ disabled, value, class စသည်တို့မှာကွာခြားချက်အရေးကြီးပါတယ်။ Child input binding တွင် parent က data owner ဖြစ်ပြီး object mutation policy ကိုတိတိကျကျထားရပါတယ်။
- `disabled="false"` ကို false property လို့ယူဆခြင်းမှားပါတယ်—attribute ရှိနေသရွေ့ disabled ဖြစ်နိုင်ပါတယ်။
- Button disabled state, image source နဲ့ child object input သုံးမျိုး bind လုပ်ပြီး boolean/object က string မဖြစ်ဘဲပို့ကြောင်းစစ်ပါ။
Angular — Templates — Angular