Thuta Learning
ရှာဖွေရန်
ProjectsWeb Developmentintermediate

Mini Project: Task Tracker (Part 1 - Setup & Structure)

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

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

  • Mini Project: Task Tracker (Part 1 - Setup & Structure) ကို လက်တွေ့ project ထဲမှာ အသုံးချတတ်မယ်
  • ကိုယ်တိုင် code ရေးပြီး run ကြည့်တတ်မယ်
  • Project တစ်ခုလုံးကို အဆင့်လိုက် ဆောက်တတ်မယ်

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

ဒီ project မှာ Angular CLI နဲ့ Task Tracker app တစ်ခုကို scratch ကနေ တည်ဆောက်သွားမှာဖြစ်ပါတယ်။ Component-based architecture, TypeScript interfaces နဲ့ routing setup တွေက Angular app တိုင်းရဲ့ foundation ဖြစ်တဲ့အတွက် ဒီ Part 1 မှာ folder structure, root component, task model interface နဲ့ list/detail route နှစ်ခုကို ပြင်ဆင်ထားမှာပါ။ Part 2 နဲ့ Part 3 တွေမှာ ဒီ structure ပေါ်မှာ feature တွေ ဆက်တည်ဆောက်သွားမှာမို့ ဒီအဆင့်ကို သေချာလုပ်ထားဖို့ အရေးကြီးပါတယ်။ Components, modules နဲ့ routing lesson တွေမှာ သင်ခဲ့တဲ့ concept တွေကို ဒီမှာ practical အနေနဲ့ ပေါင်းသုံးကြည့်ရမှာပါ။

လက်တွေ့ ဆောက်ကြည့်မယ်

Terminal မှာ `ng new task-tracker --routing --style=css` command သုံးပြီး project အသစ်တစ်ခု create လုပ်ပါ။ `src/app` အောက်မှာ `task.model.ts` file ဆောက်ပြီး `Task` interface (id, title, description, completed) ကို define လုပ်ပါ။ `TaskListComponent` နဲ့ `TaskDetailComponent` ဆိုတဲ့ component နှစ်ခု `ng generate component` နဲ့ ဆောက်ပြီး `app-routing.module.ts` မှာ path `''` ကို TaskListComponent ဆီ၊ path `task/:id` ကို TaskDetailComponent ဆီ route လုပ်ပါ။ AppComponent template ထဲမှာ `<router-outlet>` ထည့်ပြီး header title လေး ပြထားပါ။

Code နမူနာ

typescript
// src/app/task.model.ts
export interface Task {
  id: number;
  title: string;
  description: string;
  completed: boolean;
}

// src/app/app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TaskListComponent } from './task-list/task-list.component';
import { TaskDetailComponent } from './task-detail/task-detail.component';

const routes: Routes = [
  { path: '', component: TaskListComponent },
  { path: 'task/:id', component: TaskDetailComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
You should see
ng serve run ထားရင် root path '/' မှာ TaskListComponent (empty list) ပေါ်လာပြီး header title ကို browser မှာ တွေ့ရမှာဖြစ်သည်။

၅ မိနစ် စမ်းကြည့်

5 minutes အတွင်း TaskDetailComponent ထဲမှာ ActivatedRoute inject လုပ်ပြီး route param `id` ကို console.log ထုတ်ကြည့်ပါ။

သတိလေးတစ်ချက်

Project structure ကို အစပိုင်းမှာ သေချာစီစဉ်ထားခြင်းက နောက်ပိုင်း feature တွေတိုးလာတဲ့အခါ refactor လုပ်ရတာ လျော့နည်းစေပါတယ်။

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

  • app-routing.module.ts ကို AppModule ရဲ့ imports array ထဲ ထည့်ဖို့ မေ့တတ်ကြသည် (RouterModule import မလုပ်ခဲ့ရင် router-outlet အလုပ်မလုပ်ပါ)
  • Task interface မှာ id ကို string လား number လား သတ်မှတ်ထားတာ project တစ်လျှောက်လုံး consistent မဖြစ်တတ်ပါ

အခု ကိုယ်တိုင် စမ်းကြည့်

5 minutes အတွင်း TaskDetailComponent ထဲမှာ ActivatedRoute inject လုပ်ပြီး route param `id` ကို console.log ထုတ်ကြည့်ပါ။

You'll know it worked when: ng serve run ထားရင် root path '/' မှာ TaskListComponent (empty list) ပေါ်လာပြီး header title ကို browser မှာ တွေ့ရမှာဖြစ်သည်။

Mini Project: Task Tracker (Part 1 - Setup & Structure) | Thuta Learning