ရိုးရိုးလေး ရှင်းပြမယ်
Components ကို ရိုးရိုးလေးနားလည်မယ်
Component သည် Angular application ၏ အခြေခံအကျဆုံး building block ဖြစ်သည်။ Component တစ်ခုတွင် အပိုင်းသုံးပိုင်းပါဝင်သည်:
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Component တစ်ခုထဲ API call, business rules နဲ့ UI details အားလုံးပေါင်းခြင်းက test နဲ့ reuse ခက်စေပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Component တစ်ခုက UI responsibility တစ်ခုကို class state, template နဲ့ scoped styles ဖြင့် encapsulate လုပ်ပါတယ်။ Smart/container component က data loading နဲ့ coordination ကိုကိုင်ပြီး presentational component က inputs/outputs ဖြင့် predictable UI ပြနိုင်ပါတယ်။ Standalone component ၏ `imports` က template dependencies ကိုရှင်းရှင်းလင်းလင်းဖော်ပြပြီး selector က parent template ထဲအသုံးပြုမည့် public element name ဖြစ်ပါတယ်။
- Input + state
- Component + template
- Rendered Angular UI
Components ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
// user-profile.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
styleUrls: ['./user-profile.component.css']
})
export class UserProfileComponent {
username = 'John Doe';
}Component တစ်ခုက UI responsibility တစ်ခုကို class state, template နဲ့ scoped styles ဖြင့် encapsulate လုပ်ပါတယ်။ Smart/container component က data loading နဲ့ coordination ကိုကိုင်ပြီး presentational component က inputs/outputs ဖြင့် predictable UI ပြနိုင်ပါတယ်။ Standalone component ၏ `imports` က template dependencies ကိုရှင်းရှင်းလင်းလင်းဖော်ပြပြီး selector က parent template ထဲအသုံးပြုမည့် public element name ဖြစ်ပါတယ်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
// user-profile.component.tsComponent သည် Angular application ၏ အခြေခံအကျဆုံး building block ဖြစ်သည်။ Component တစ်ခုတွင် အပိုင်းသုံးပိုင်းပါဝင်သည်:
- Component + template
styleUrls: ['./user-profile.component.css']Component တစ်ခုက UI responsibility တစ်ခုကို class state, template နဲ့ scoped styles ဖြင့် encapsulate လုပ်ပါတယ်။ Smart/container component က data loading နဲ့ coordination ကိုကိုင်ပြီး presentational component က inputs/outputs ဖြင့် predictable UI ပြနိုင်ပါတယ်။ Standalone component ၏ `imports` က template dependencies ကိုရှင်းရှင်းလင်းလင်းဖော်ပြပြီး selector က parent template ထဲအသုံးပြုမည့် public element name ဖြစ်ပါတယ်။
- Rendered Angular UI
}Profile card component ကို inputs ပါသော child နဲ့ data ပိုင်သော parent နှစ်ပိုင်းခွဲပြီး reusable ဖြစ်မဖြစ် data set နှစ်ခုနဲ့စမ်းပါ။
- Input + state
- Component + template
- Rendered Angular UI
Success
Components ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
Component တစ်ခုထဲ API call, business rules နဲ့ UI details အားလုံးပေါင်းခြင်းက test နဲ့ reuse ခက်စေပါတယ်။
Component သည် Angular application ၏ အခြေခံအကျဆုံး building block ဖြစ်သည်။ Component တစ်ခုတွင် အပိုင်းသုံးပိုင်းပါဝင်သည်:
• TypeScript Class: Component ၏ logic နှင့် data များ (properties & methods)
• HTML Template: Component ၏ UI
• CSS Styles: Component အတွက်သာသက်ဆိုင်သော styles များ
// user-profile.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
styleUrls: ['./user-profile.component.css']
})
export class UserProfileComponent {
username = 'John Doe';
}(HTML template တွင် {{ username }} ကိုသုံးခြင်းဖြင့် 'John Doe' ဟုပြသမည်)Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Profile card component ကို inputs ပါသော child နဲ့ data ပိုင်သော parent နှစ်ပိုင်းခွဲပြီး reusable ဖြစ်မဖြစ် data set နှစ်ခုနဲ့စမ်းပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Components နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
// user-profile.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
styleUrls: ['./user-profile.component.css']
})
export class UserProfileComponent {
username = 'John Doe';
}ရလဒ်: Components ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Profile card component ကို inputs ပါသော child နဲ့ data ပိုင်သော parent နှစ်ပိုင်းခွဲပြီး reusable ဖြစ်မဖြစ် data set နှစ်ခုနဲ့စမ်းပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Input + state → Component + template → Rendered Angular UI
- Component တစ်ခုက UI responsibility တစ်ခုကို class state, template နဲ့ scoped styles ဖြင့် encapsulate လုပ်ပါတယ်။ Smart/container component က data loading နဲ့ coordination ကိုကိုင်ပြီး presentational component က inputs/outputs ဖြင့် predictable UI ပြနိုင်ပါတယ်။ Standalone component ၏ `imports` က template dependencies ကိုရှင်းရှင်းလင်းလင်းဖော်ပြပြီး selector က parent template ထဲအသုံးပြုမည့် public element name ဖြစ်ပါတယ်။
- Component တစ်ခုထဲ API call, business rules နဲ့ UI details အားလုံးပေါင်းခြင်းက test နဲ့ reuse ခက်စေပါတယ်။
- Profile card component ကို inputs ပါသော child နဲ့ data ပိုင်သော parent နှစ်ပိုင်းခွဲပြီး reusable ဖြစ်မဖြစ် data set နှစ်ခုနဲ့စမ်းပါ။
Angular — Components — Angular