ရိုးရိုးလေး ရှင်းပြမယ်
Mini Project: Task Tracker (Part 2 - Core Feature ထည့်ခြင်း) ကို ရိုးရိုးလေးနားလည်မယ်
Part 1 မှာ ဆောက်ထားတဲ့ structure ပေါ်မှာ Part 2 မှာတော့ app ရဲ့ core feature ဖြစ်တဲ့ task add/list/toggle functionality ကို ထည့်သွားမှာပါ။ Service, dependency injection, reactive forms, *ngFor directive နဲ့ two-way binding lesson တွေက ဒီအဆင့်အတွက် အခြေခံအားလုံးဖြစ်ပါတယ်။ Component တွေအကြား data ကို share လုပ်ဖို့ TaskService တစ်ခု ဗဟိုချုပ်ကိုင်ပြီး BehaviorSubject နဲ့ task list ကို manage လုပ်သွားမှာဖြစ်ပါတယ်။ ဒီလိုလုပ်ခြင်းအားဖြင့် component logic တွေ ရိုးရှင်းပြီး reusable ဖြစ်လာပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Filtered list ကိုsource list အဖြစ်ပြန်သိမ်းခြင်းက filter ပြောင်းချိန် tasks ပျောက်သလိုဖြစ်စေနိုင်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Part 2 မှာ add, toggle, delete နဲ့ filter တို့ကို explicit state transitions အဖြစ်တည်ဆောက်ပါတယ်။ Form validation ကိုUI boundary မှာထားပြီး state service က immutable updates နဲ့ readonly view model ပေးသင့်ပါတယ်။ Derived counts/filter results ကိုsource state ထဲ duplicate မသိမ်းဘဲ computed stream/signal ဖြင့်တွက်ပါ။
- Project requirements
- Components + state + services
- စမ်းသပ်ပြီး UI
Mini Project: Task Tracker (Part 2 - Core Feature ထည့်ခြင်း) ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
// task.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Task } from './task.model';
@Injectable({ providedIn: 'root' })
export class TaskService {
private tasksSubject = new BehaviorSubject<Task[]>([]);
tasks$ = this.tasksSubject.asObservable();
private nextId = 1;
getTasks() {
return this.tasks$;
}
addTask(title: string, description: string) {
const current = this.tasksSubject.value;
const newTask: Task = { id: this.nextId++, title, description, completed: false };
this.tasksSubject.next([...current, newTask]);
}
toggleComplete(id: number) {
const updated = this.tasksSubject.value.map(t =>
t.id === id ? { ...t, completed: !t.completed } : t
);
this.tasksSubject.next(updated);
}
}Part 2 မှာ add, toggle, delete နဲ့ filter တို့ကို explicit state transitions အဖြစ်တည်ဆောက်ပါတယ်။ Form validation ကိုUI boundary မှာထားပြီး state service က immutable updates နဲ့ readonly view model ပေးသင့်ပါတယ်။ Derived counts/filter results ကိုsource state ထဲ duplicate မသိမ်းဘဲ computed stream/signal ဖြင့်တွက်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Project requirements
// task.service.tsPart 1 မှာ ဆောက်ထားတဲ့ structure ပေါ်မှာ Part 2 မှာတော့ app ရဲ့ core feature ဖြစ်တဲ့ task add/list/toggle functionality ကို ထည့်သွားမှာပါ။ Service, dependency injection, reactive forms, *ngFor directive နဲ့ two-way binding lesson တွေက ဒီအဆင့်အတွက် အခြေခံအားလုံးဖြစ်ပါတယ်။ Component တွေအကြား data ကို share လုပ်ဖို့ TaskService တစ်ခု ဗဟိုချုပ်ကိုင်ပြီး BehaviorSubject နဲ့ task list ကို manage လုပ်သွားမှာဖြစ်ပါတယ်။ ဒီလိုလုပ်ခြင်းအားဖြင့် component logic တွေ ရိုးရှင်းပြီး reusable ဖြစ်လာပါတယ်။
- Components + state + services
addTask(title: string, description: string) {Part 2 မှာ add, toggle, delete နဲ့ filter တို့ကို explicit state transitions အဖြစ်တည်ဆောက်ပါတယ်။ Form validation ကိုUI boundary မှာထားပြီး state service က immutable updates နဲ့ readonly view model ပေးသင့်ပါတယ်။ Derived counts/filter results ကိုsource state ထဲ duplicate မသိမ်းဘဲ computed stream/signal ဖြင့်တွက်ပါ။
- စမ်းသပ်ပြီး UI
}Add form, task row outputs, filter buttons နဲ့ remaining count တည်ဆောက်ပါ။ Duplicate/empty title, rapid toggles နဲ့ deleting selected detail task ကိုစမ်းပါ။
- Project requirements
- Components + state + services
- စမ်းသပ်ပြီး UI
Success
Mini Project: Task Tracker (Part 2 - Core Feature ထည့်ခြင်း) ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
Filtered list ကိုsource list အဖြစ်ပြန်သိမ်းခြင်းက filter ပြောင်းချိန် tasks ပျောက်သလိုဖြစ်စေနိုင်ပါတယ်။
ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Part 1 မှာ ဆောက်ထားတဲ့ structure ပေါ်မှာ Part 2 မှာတော့ app ရဲ့ core feature ဖြစ်တဲ့ task add/list/toggle functionality ကို ထည့်သွားမှာပါ။ Service, dependency injection, reactive forms, *ngFor directive နဲ့ two-way binding lesson တွေက ဒီအဆင့်အတွက် အခြေခံအားလုံးဖြစ်ပါတယ်။ Component တွေအကြား data ကို share လုပ်ဖို့ TaskService တစ်ခု ဗဟိုချုပ်ကိုင်ပြီး BehaviorSubject နဲ့ task list ကို manage လုပ်သွားမှာဖြစ်ပါတယ်။ ဒီလိုလုပ်ခြင်းအားဖြင့် component logic တွေ ရိုးရှင်းပြီး reusable ဖြစ်လာပါတယ်။
လက်တွေ့ ဆောက်ကြည့်မယ်
`TaskService` ကို `ng generate service task` နဲ့ ဆောက်ပြီး internal BehaviorSubject<Task[]> တစ်ခုနဲ့ `getTasks()`, `addTask(task)`, `toggleComplete(id)` method သုံးခု implement လုပ်ပါ။ TaskListComponent မှာ FormGroup (title, description) တစ်ခုနဲ့ new task ထည့်ရန် form တည်ဆောက်ပြီး submit ဖြစ်ရင် service.addTask() ခေါ်ပါ။ Task list ကို *ngFor နဲ့ loop ပြီး checkbox တစ်ခုစီအတွက် [(ngModel)] နဲ့ completed status ကို toggle လုပ်နိုင်အောင် ချိတ်ဆက်ပါ။ Completed task တွေကို ngClass နဲ့ strikethrough style ပေးပါ။
Code နမူနာ
// task.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Task } from './task.model';
@Injectable({ providedIn: 'root' })
export class TaskService {
private tasksSubject = new BehaviorSubject<Task[]>([]);
tasks$ = this.tasksSubject.asObservable();
private nextId = 1;
getTasks() {
return this.tasks$;
}
addTask(title: string, description: string) {
const current = this.tasksSubject.value;
const newTask: Task = { id: this.nextId++, title, description, completed: false };
this.tasksSubject.next([...current, newTask]);
}
toggleComplete(id: number) {
const updated = this.tasksSubject.value.map(t =>
t.id === id ? { ...t, completed: !t.completed } : t
);
this.tasksSubject.next(updated);
}
}Form ကနေ task title/description ရိုက်ပြီး submit လုပ်ရင် list ထဲမှာ task အသစ်တစ်ခု ချက်ချင်းပေါ်လာပြီး checkbox click လုပ်ရင် strikethrough style ပြောင်းသွားမှာဖြစ်သည်။Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Add form, task row outputs, filter buttons နဲ့ remaining count တည်ဆောက်ပါ။ Duplicate/empty title, rapid toggles နဲ့ deleting selected detail task ကိုစမ်းပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Mini Project: Task Tracker (Part 2 - Core Feature ထည့်ခြင်း) နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
// task.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Task } from './task.model';
@Injectable({ providedIn: 'root' })
export class TaskService {
private tasksSubject = new BehaviorSubject<Task[]>([]);
tasks$ = this.tasksSubject.asObservable();
private nextId = 1;
getTasks() {
return this.tasks$;
}
addTask(title: string, description: string) {
const current = this.tasksSubject.value;
const newTask: Task = { id: this.nextId++, title, description, completed: false };
this.tasksSubject.next([...current, newTask]);
}
toggleComplete(id: number) {
const updated = this.tasksSubject.value.map(t =>
t.id === id ? { ...t, completed: !t.completed } : t
);
this.tasksSubject.next(updated);
}
}ရလဒ်: Mini Project: Task Tracker (Part 2 - Core Feature ထည့်ခြင်း) ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Add form, task row outputs, filter buttons နဲ့ remaining count တည်ဆောက်ပါ။ Duplicate/empty title, rapid toggles နဲ့ deleting selected detail task ကိုစမ်းပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Project requirements → Components + state + services → စမ်းသပ်ပြီး UI
- Part 2 မှာ add, toggle, delete နဲ့ filter တို့ကို explicit state transitions အဖြစ်တည်ဆောက်ပါတယ်။ Form validation ကိုUI boundary မှာထားပြီး state service က immutable updates နဲ့ readonly view model ပေးသင့်ပါတယ်။ Derived counts/filter results ကိုsource state ထဲ duplicate မသိမ်းဘဲ computed stream/signal ဖြင့်တွက်ပါ။
- Filtered list ကိုsource list အဖြစ်ပြန်သိမ်းခြင်းက filter ပြောင်းချိန် tasks ပျောက်သလိုဖြစ်စေနိုင်ပါတယ်။
- Add form, task row outputs, filter buttons နဲ့ remaining count တည်ဆောက်ပါ။ Duplicate/empty title, rapid toggles နဲ့ deleting selected detail task ကိုစမ်းပါ။
Angular — Overview — Angular