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

Exercise Set 1: Components, Binding & Directives

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

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

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

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

Exercise Set 1: Components, Binding & Directives ကို ရိုးရိုးလေးနားလည်မယ်

ဒီ exercise set က Angular ရဲ့ အခြေခံဆုံး building block တွေဖြစ်တဲ့ component, data binding (property/event/two-way) နဲ့ structural directives (*ngIf, *ngFor, *ngSwitch) ကို လက်တွေ့ကျ ကျင့်သားရအောင် ရည်ရွယ်ထားပါတယ်။ Task တစ်ခုချင်းစီဟာ standalone အနေနဲ့ လုပ်လို့ရပြီး Basic chapter မှာ သင်ခဲ့တဲ့ concept တွေကို memory refresh လုပ်ဖို့ အသုံးဝင်ပါတယ်။ Solution ကို ကိုယ်ပိုင် attempt လုပ်ကြည့်ပြီးမှ answer ကို reference အနေနဲ့ ကြည့်ဖို့ အကြံပြုပါတယ်။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

Screen မှာ sample တစ်ခုပေါ်တာနဲ့ပြီးပြီလို့ယူဆခြင်းက empty state, repeated items နဲ့ accessibility bugs ကိုလွတ်စေပါတယ်။

ဖြစ်လေ့ရှိတဲ့အမှား

Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

ဒီ exercise set က component boundaries, template binding, events နဲ့ directives ကိုပေါင်းစပ်နိုင်မှုကိုစမ်းပါတယ်။ Task တစ်ခုစီအတွက် state owner, inputs, outputs နဲ့ render branches ကိုcode မရေးမီသတ်မှတ်ပါ။ Normal, empty, invalid နဲ့ reorder cases စမ်းပြီး semantic HTML နဲ့ keyboard behavior ကိုလည်း acceptance criteria ထဲထည့်ပါ။

Mental Model
  1. လိုအပ်ချက်
  2. စဉ်းစားပြီး implement
  3. စမ်းသပ်ပြီးရှင်းပြ

Exercise Set 1: Components, Binding & Directives ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

typescript
// profile-card.component.ts
import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-profile-card',
  template: `
    <div class="card">
      <h3>{{ name }}</h3>
      <p>Age: {{ age }}</p>
    </div>
  `
})
export class ProfileCardComponent {
  @Input() name = '';
  @Input() age = 0;
}

// counter.component.ts (task 2 skeleton)
import { Component } from '@angular/core';

@Component({
  selector: 'app-counter',
  template: `
    <p>Count: {{ count }}</p>
    <button (click)="increment()">+1</button>
  `
})
export class CounterComponent {
  count = 0;
  increment() {
    this.count++;
  }
}

ဒီ exercise set က component boundaries, template binding, events နဲ့ directives ကိုပေါင်းစပ်နိုင်မှုကိုစမ်းပါတယ်။ Task တစ်ခုစီအတွက် state owner, inputs, outputs နဲ့ render branches ကိုcode မရေးမီသတ်မှတ်ပါ။ Normal, empty, invalid နဲ့ reorder cases စမ်းပြီး semantic HTML နဲ့ keyboard behavior ကိုလည်း acceptance criteria ထဲထည့်ပါ။

Code ကို အဆင့်လိုက်ဖတ်မယ်

  1. လိုအပ်ချက်// profile-card.component.ts

    ဒီ exercise set က Angular ရဲ့ အခြေခံဆုံး building block တွေဖြစ်တဲ့ component, data binding (property/event/two-way) နဲ့ structural directives (*ngIf, *ngFor, *ngSwitch) ကို လက်တွေ့ကျ ကျင့်သားရအောင် ရည်ရွယ်ထားပါတယ်။ Task တစ်ခုချင်းစီဟာ standalone အနေနဲ့ လုပ်လို့ရပြီး Basic chapter မှာ သင်ခဲ့တဲ့ concept တွေကို memory refresh လုပ်ဖို့ အသုံးဝင်ပါတယ်။ Solution ကို ကိုယ်ပိုင် attempt လုပ်ကြည့်ပြီးမှ answer ကို reference အနေနဲ့ ကြည့်ဖို့ အကြံပြုပါတယ်။

  2. စဉ်းစားပြီး implement// counter.component.ts (task 2 skeleton)

    ဒီ exercise set က component boundaries, template binding, events နဲ့ directives ကိုပေါင်းစပ်နိုင်မှုကိုစမ်းပါတယ်။ Task တစ်ခုစီအတွက် state owner, inputs, outputs နဲ့ render branches ကိုcode မရေးမီသတ်မှတ်ပါ။ Normal, empty, invalid နဲ့ reorder cases စမ်းပြီး semantic HTML နဲ့ keyboard behavior ကိုလည်း acceptance criteria ထဲထည့်ပါ။

  3. စမ်းသပ်ပြီးရှင်းပြ}

    Challenge တစ်ခုစီကို component diagram → implementation → behavior tests → refactor အစဉ်နဲ့လုပ်ပြီး input/output contracts ကိုရေးတင်ပါ။

Execution Flow
  1. လိုအပ်ချက်
  2. စဉ်းစားပြီး implement
  3. စမ်းသပ်ပြီးရှင်းပြ

Success

Exercise Set 1: Components, Binding & Directives ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

Failure

Screen မှာ sample တစ်ခုပေါ်တာနဲ့ပြီးပြီလို့ယူဆခြင်းက empty state, repeated items နဲ့ accessibility bugs ကိုလွတ်စေပါတယ်။

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ exercise set က Angular ရဲ့ အခြေခံဆုံး building block တွေဖြစ်တဲ့ component, data binding (property/event/two-way) နဲ့ structural directives (*ngIf, *ngFor, *ngSwitch) ကို လက်တွေ့ကျ ကျင့်သားရအောင် ရည်ရွယ်ထားပါတယ်။ Task တစ်ခုချင်းစီဟာ standalone အနေနဲ့ လုပ်လို့ရပြီး Basic chapter မှာ သင်ခဲ့တဲ့ concept တွေကို memory refresh လုပ်ဖို့ အသုံးဝင်ပါတယ်။ Solution ကို ကိုယ်ပိုင် attempt လုပ်ကြည့်ပြီးမှ answer ကို reference အနေနဲ့ ကြည့်ဖို့ အကြံပြုပါတယ်။

လေ့ကျင့်ခန်းများ

(1) `ProfileCardComponent` တစ်ခု ဆောက်ပြီး @Input() name, age ကို property binding နဲ့ ပြပါ။ (2) Button click တစ်ခုနဲ့ counter number ကို increment လုပ်ဖို့ event binding [(click)] အသုံးပြုပါ။ (3) Text input field တစ်ခုကို [(ngModel)] နဲ့ two-way bind လုပ်ပြီး ရိုက်ထည့်တဲ့ text ကို real-time preview ပြပါ။ (4) Array of string 5 ခုကို *ngFor နဲ့ list ပြပြီး array empty ဖြစ်ရင် "No items" ဆိုတဲ့ message ကို *ngIf နဲ့ ပြပါ။

Code နမူနာ

typescript
// profile-card.component.ts
import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-profile-card',
  template: `
    <div class="card">
      <h3>{{ name }}</h3>
      <p>Age: {{ age }}</p>
    </div>
  `
})
export class ProfileCardComponent {
  @Input() name = '';
  @Input() age = 0;
}

// counter.component.ts (task 2 skeleton)
import { Component } from '@angular/core';

@Component({
  selector: 'app-counter',
  template: `
    <p>Count: {{ count }}</p>
    <button (click)="increment()">+1</button>
  `
})
export class CounterComponent {
  count = 0;
  increment() {
    this.count++;
  }
}
You should see
Task 4 ခုစလုံးပြီးရင် profile card ပေါ်နေပြီး counter button နှိပ်တိုင်း number တိုးလာကာ input field ထဲရိုက်တာနဲ့ preview text ချက်ချင်းပြောင်းပြီး list/empty message မှန်ကန်စွာပြသည်။

Real-world usage

လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ

Challenge တစ်ခုစီကို component diagram → implementation → behavior tests → refactor အစဉ်နဲ့လုပ်ပြီး input/output contracts ကိုရေးတင်ပါ။

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

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

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
typescript
// profile-card.component.ts
import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-profile-card',
  template: `
    <div class="card">
      <h3>{{ name }}</h3>
      <p>Age: {{ age }}</p>
    </div>
  `
})
export class ProfileCardComponent {
  @Input() name = '';
  @Input() age = 0;
}

// counter.component.ts (task 2 skeleton)
import { Component } from '@angular/core';

@Component({
  selector: 'app-counter',
  template: `
    <p>Count: {{ count }}</p>
    <button (click)="increment()">+1</button>
  `
})
export class CounterComponent {
  count = 0;
  increment() {
    this.count++;
  }
}

ရလဒ်: Exercise Set 1: Components, Binding & Directives ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

အရိပ်အမြွက် ကြည့်ရန်

Challenge တစ်ခုစီကို component diagram → implementation → behavior tests → refactor အစဉ်နဲ့လုပ်ပြီး input/output contracts ကိုရေးတင်ပါ။

Quick Quiz 1 / 3

Exercise Set 1: Components, Binding & Directives ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

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

Quick Quiz 3 / 3

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

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

  • လိုအပ်ချက် → စဉ်းစားပြီး implement → စမ်းသပ်ပြီးရှင်းပြ
  • ဒီ exercise set က component boundaries, template binding, events နဲ့ directives ကိုပေါင်းစပ်နိုင်မှုကိုစမ်းပါတယ်။ Task တစ်ခုစီအတွက် state owner, inputs, outputs နဲ့ render branches ကိုcode မရေးမီသတ်မှတ်ပါ။ Normal, empty, invalid နဲ့ reorder cases စမ်းပြီး semantic HTML နဲ့ keyboard behavior ကိုလည်း acceptance criteria ထဲထည့်ပါ။
  • Screen မှာ sample တစ်ခုပေါ်တာနဲ့ပြီးပြီလို့ယူဆခြင်းက empty state, repeated items နဲ့ accessibility bugs ကိုလွတ်စေပါတယ်။
  • Challenge တစ်ခုစီကို component diagram → implementation → behavior tests → refactor အစဉ်နဲ့လုပ်ပြီး input/output contracts ကိုရေးတင်ပါ။

Angular — Overview — Angular

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

  • Screen မှာ sample တစ်ခုပေါ်တာနဲ့ပြီးပြီလို့ယူဆခြင်းက empty state, repeated items နဲ့ accessibility bugs ကိုလွတ်စေပါတယ်။
  • Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။

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

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

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Task 4 ခုစလုံးပြီးရင် profile card ပေါ်နေပြီး counter button နှိပ်တိုင်း number တိုးလာကာ input field ထဲရိုက်တာနဲ့ preview text ချက်ချင်းပြောင်းပြီး list/empty message မှန်ကန်စွာပြသည်။

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

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

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

Exercise Set 1: Components, Binding & Directives | Thuta Learning