Thuta Learning
Angular
BasicWeb Developmentအလယ်အလတ်

Components

Angularသင်ခန်းစာ 520 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Components ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
  • နမူနာ UI ကို run၊ state/output ခန့်မှန်းပြီး edge/error cases စမ်းနိုင်ရန်
  • လက်တွေ့ project တွင် typed safe pattern နဲ့ common pitfalls ကိုခွဲသိနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

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 ဖြစ်ပါတယ်။

Mental Model
  1. Input + state
  2. Component + template
  3. Rendered Angular UI

Components ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

typescript
// 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 ကို အဆင့်လိုက်ဖတ်မယ်

  1. Input + state// user-profile.component.ts

    Component သည် Angular application ၏ အခြေခံအကျဆုံး building block ဖြစ်သည်။ Component တစ်ခုတွင် အပိုင်းသုံးပိုင်းပါဝင်သည်:

  2. Component + templatestyleUrls: ['./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 ဖြစ်ပါတယ်။

  3. Rendered Angular UI}

    Profile card component ကို inputs ပါသော child နဲ့ data ပိုင်သော parent နှစ်ပိုင်းခွဲပြီး reusable ဖြစ်မဖြစ် data set နှစ်ခုနဲ့စမ်းပါ။

Execution Flow
  1. Input + state
  2. Component + template
  3. 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 များ

typescript
// 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';
}
You should see
(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 ကိုခန့်မှန်းပါ
typescript
// 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

Components ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • 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

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Component တစ်ခုထဲ API call, business rules နဲ့ UI details အားလုံးပေါင်းခြင်းက test နဲ့ reuse ခက်စေပါတယ်။
  • Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။

လက်တွေ့လေ့ကျင့်ခန်း

Components နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: (HTML template တွင် {{ username }} ကိုသုံးခြင်းဖြင့် 'John Doe' ဟုပြသမည်)

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Components | Thuta Learning