ရိုးရိုးလေး ရှင်းပြမယ်
Templates & Interpolation ကို ရိုးရိုးလေးနားလည်မယ်
Component ၏ UI ကို HTML ဖြင့်ရေးသားသည်။ Interpolation {{...}} ကို အသုံးပြုပြီး TypeScript class မှ data များကို template ထဲတွင် ပြသနိုင်သည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Template ထဲ function heavy တစ်ခုကိုတိုက်ရိုက်ခေါ်ခြင်းက change detection တစ်ကြိမ်စီမှာထပ်တွက်နိုင်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Angular template က declarative view ဖြစ်ပြီး interpolation, bindings, control flow နဲ့ template variables တို့ဖြင့် component state ကို UI အဖြစ်ဖော်ပြပါတယ်။ Template expression များကို side-effect နည်းပြီး မြန်ဆန်အောင်ထားကာ complex derivation ကို computed state သို့ class method မဟုတ်သော cached abstraction ထဲရွှေ့ပါ။ Escaping က text interpolation ကိုကာကွယ်ပေးသော်လည်း trusted HTML နှင့် DOM APIs သုံးရာမှာ security boundary ကိုသတိထားရပါတယ်။
- Input + state
- Component + template
- Rendered Angular UI
Templates & Interpolation ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
<div>
<h2>User Profile</h2>
<p>Username: {{ username }}</p>
<p>Account Age: {{ getAccountAge() }} years</p>
</div>
// user-profile.component.ts
export class UserProfileComponent {
username = 'Jane Doe';
getAccountAge() {
return 2;
}
}Angular template က declarative view ဖြစ်ပြီး interpolation, bindings, control flow နဲ့ template variables တို့ဖြင့် component state ကို UI အဖြစ်ဖော်ပြပါတယ်။ Template expression များကို side-effect နည်းပြီး မြန်ဆန်အောင်ထားကာ complex derivation ကို computed state သို့ class method မဟုတ်သော cached abstraction ထဲရွှေ့ပါ။ Escaping က text interpolation ကိုကာကွယ်ပေးသော်လည်း trusted HTML နှင့် DOM APIs သုံးရာမှာ security boundary ကိုသတိထားရပါတယ်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
<div>Component ၏ UI ကို HTML ဖြင့်ရေးသားသည်။ Interpolation {{...}} ကို အသုံးပြုပြီး TypeScript class မှ data များကို template ထဲတွင် ပြသနိုင်သည်။
- Component + template
export class UserProfileComponent {Angular template က declarative view ဖြစ်ပြီး interpolation, bindings, control flow နဲ့ template variables တို့ဖြင့် component state ကို UI အဖြစ်ဖော်ပြပါတယ်။ Template expression များကို side-effect နည်းပြီး မြန်ဆန်အောင်ထားကာ complex derivation ကို computed state သို့ class method မဟုတ်သော cached abstraction ထဲရွှေ့ပါ။ Escaping က text interpolation ကိုကာကွယ်ပေးသော်လည်း trusted HTML နှင့် DOM APIs သုံးရာမှာ security boundary ကိုသတိထားရပါတယ်။
- Rendered Angular UI
}Product object တစ်ခုကို interpolation နဲ့ပြပြီး missing data fallback, formatted price နဲ့ derived label တို့ထည့်ပါ။ Template expression တစ်ခုချင်းစီကိုဘယ်လောက်မကြာခဏတွက်နိုင်သလဲစဉ်းစားပါ။
- Input + state
- Component + template
- Rendered Angular UI
Success
Templates & Interpolation ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
Template ထဲ function heavy တစ်ခုကိုတိုက်ရိုက်ခေါ်ခြင်းက change detection တစ်ကြိမ်စီမှာထပ်တွက်နိုင်ပါတယ်။
Component ၏ UI ကို HTML ဖြင့်ရေးသားသည်။ Interpolation {{...}} ကို အသုံးပြုပြီး TypeScript class မှ data များကို template ထဲတွင် ပြသနိုင်သည်။
<div>
<h2>User Profile</h2>
<p>Username: {{ username }}</p>
<p>Account Age: {{ getAccountAge() }} years</p>
</div>
// user-profile.component.ts
export class UserProfileComponent {
username = 'Jane Doe';
getAccountAge() {
return 2;
}
}(Browser တွင် 'Username: Jane Doe' နှင့် 'Account Age: 2 years' ဟု ပေါ်လာမည်)Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Product object တစ်ခုကို interpolation နဲ့ပြပြီး missing data fallback, formatted price နဲ့ derived label တို့ထည့်ပါ။ Template expression တစ်ခုချင်းစီကိုဘယ်လောက်မကြာခဏတွက်နိုင်သလဲစဉ်းစားပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Templates & Interpolation နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
<div>
<h2>User Profile</h2>
<p>Username: {{ username }}</p>
<p>Account Age: {{ getAccountAge() }} years</p>
</div>
// user-profile.component.ts
export class UserProfileComponent {
username = 'Jane Doe';
getAccountAge() {
return 2;
}
}ရလဒ်: Templates & Interpolation ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Product object တစ်ခုကို interpolation နဲ့ပြပြီး missing data fallback, formatted price နဲ့ derived label တို့ထည့်ပါ။ Template expression တစ်ခုချင်းစီကိုဘယ်လောက်မကြာခဏတွက်နိုင်သလဲစဉ်းစားပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Input + state → Component + template → Rendered Angular UI
- Angular template က declarative view ဖြစ်ပြီး interpolation, bindings, control flow နဲ့ template variables တို့ဖြင့် component state ကို UI အဖြစ်ဖော်ပြပါတယ်။ Template expression များကို side-effect နည်းပြီး မြန်ဆန်အောင်ထားကာ complex derivation ကို computed state သို့ class method မဟုတ်သော cached abstraction ထဲရွှေ့ပါ။ Escaping က text interpolation ကိုကာကွယ်ပေးသော်လည်း trusted HTML နှင့် DOM APIs သုံးရာမှာ security boundary ကိုသတိထားရပါတယ်။
- Template ထဲ function heavy တစ်ခုကိုတိုက်ရိုက်ခေါ်ခြင်းက change detection တစ်ကြိမ်စီမှာထပ်တွက်နိုင်ပါတယ်။
- Product object တစ်ခုကို interpolation နဲ့ပြပြီး missing data fallback, formatted price နဲ့ derived label တို့ထည့်ပါ။ Template expression တစ်ခုချင်းစီကိုဘယ်လောက်မကြာခဏတွက်နိုင်သလဲစဉ်းစားပါ။
Angular — Templates — Angular