Let's think about this for a moment
In this project, we'll build a Task Tracker app from scratch using the Angular CLI. Component-based architecture, TypeScript interfaces, and routing setup are the foundation of every Angular app, so in Part 1 we'll prepare the folder structure, root component, task model interface, and two routes (list/detail). Since Part 2 and Part 3 will keep building features on top of this structure, it's important to get this stage right. Here we'll bring together, in a practical way, the concepts you learned in the components, modules, and routing lessons.
Let's build it for real
In the terminal, create a new project with `ng new task-tracker --routing --style=css`. Under `src/app`, create a `task.model.ts` file and define a `Task` interface (id, title, description, completed). Build two components, `TaskListComponent` and `TaskDetailComponent`, using `ng generate component`, then in `app-routing.module.ts` route path `''` to TaskListComponent and path `task/:id` to TaskDetailComponent. Add `<router-outlet>` in the AppComponent template and show a header title.
Code Example
// 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 { }With ng serve running, the root path '/' shows TaskListComponent (empty list), and you'll see the header title in the browser.5-Minute Try-It
Within 5 minutes, inject ActivatedRoute in TaskDetailComponent and console.log the route param `id`.
A Quick Word of Caution
Carefully organizing your project structure from the start means less refactoring when new features get added later.