Angular Mini Project: Task Board
Let's combine everything into a small but complete app: a Kanban-style task board with three columns — To do, Doing and Done. You'll be able to add tasks, move them between columns, filter them and keep them after a page reload.
What you'll use: a typed model, a service with signals, computed(), effect(), input()/output(), @for with track, @if, reactive forms and component styles.
ng new task-board --style=css --ssr=false --defaults
cd task-board
ng g service board-store
ng g component task-card
ng g component add-task-formCREATE task-board/... (project files)
✔ Packages installed successfully.
CREATE src/app/board-store.ts (139 bytes)
CREATE src/app/board-store.spec.ts (368 bytes)
CREATE src/app/task-card/task-card.ts (210 bytes)
CREATE src/app/task-card/task-card.html (25 bytes)
CREATE src/app/task-card/task-card.css (0 bytes)
CREATE src/app/task-card/task-card.spec.ts (584 bytes)
CREATE src/app/add-task-form/add-task-form.ts (220 bytes)
CREATE src/app/add-task-form/add-task-form.html (29 bytes)
CREATE src/app/add-task-form/add-task-form.css (0 bytes)
CREATE src/app/add-task-form/add-task-form.spec.ts (612 bytes)
Step 1: The model and the store logic
Start with the data. A task has an id, a title, a status and a priority. The store's job is to add tasks, move them and group them by column — all immutably. Because this is plain logic, you can develop and check it right here before touching Angular:
type Status = 'todo' | 'doing' | 'done';
type Priority = 'low' | 'high';
interface Task { id: number; title: string; status: Status; priority: Priority; }
const ORDER: Status[] = ['todo', 'doing', 'done'];
class BoardLogic {
private nextId = 1;
tasks: Task[] = [];
add(title: string, priority: Priority = 'low'): void {
this.tasks = [...this.tasks, { id: this.nextId++, title: title.trim(), status: 'todo', priority }];
}
move(id: number, direction: 1 | -1): void {
this.tasks = this.tasks.map((t) => {
if (t.id !== id) return t;
const i = Math.min(ORDER.length - 1, Math.max(0, ORDER.indexOf(t.status) + direction));
return { ...t, status: ORDER[i] };
});
}
remove(id: number): void {
this.tasks = this.tasks.filter((t) => t.id !== id);
}
columns(): Record<Status, string[]> {
const cols: Record<Status, string[]> = { todo: [], doing: [], done: [] };
for (const t of this.tasks) cols[t.status].push(`${t.title}${t.priority === 'high' ? ' (!)' : ''}`);
return cols;
}
}
const board = new BoardLogic();
board.add('Design the model', 'high');
board.add('Build the store');
board.add('Create task cards');
board.add('Write tests');
board.move(1, 1);
board.move(1, 1);
board.move(2, 1);
board.move(1, 1); // already done: stays done
board.remove(4);
console.log(board.columns());{
todo: [ 'Create task cards' ],
doing: [ 'Build the store' ],
done: [ 'Design the model (!)' ]
}
Step 2: The store as an Angular service
Now wrap the same logic in a root-provided service with signals. computed() groups the tasks by column, and an effect() saves them to localStorage whenever they change:
// src/app/board-store.ts
import { Injectable, computed, effect, signal } from '@angular/core';
export type Status = 'todo' | 'doing' | 'done';
export type Priority = 'low' | 'high';
export interface Task { id: number; title: string; status: Status; priority: Priority; }
const ORDER: Status[] = ['todo', 'doing', 'done'];
const KEY = 'task-board';
@Injectable({ providedIn: 'root' })
export class BoardStore {
private readonly _tasks = signal<Task[]>(JSON.parse(localStorage.getItem(KEY) ?? '[]'));
readonly tasks = this._tasks.asReadonly();
readonly filter = signal('');
readonly columns = computed(() => {
const q = this.filter().toLowerCase();
const visible = this._tasks().filter((t) => t.title.toLowerCase().includes(q));
return ORDER.map((status) => ({ status, tasks: visible.filter((t) => t.status === status) }));
});
readonly progress = computed(() => {
const all = this._tasks();
return all.length ? Math.round((all.filter((t) => t.status === 'done').length / all.length) * 100) : 0;
});
constructor() {
effect(() => localStorage.setItem(KEY, JSON.stringify(this._tasks())));
}
add(title: string, priority: Priority) {
const id = Math.max(0, ...this._tasks().map((t) => t.id)) + 1;
this._tasks.update((ts) => [...ts, { id, title: title.trim(), status: 'todo', priority }]);
}
move(id: number, direction: 1 | -1) {
this._tasks.update((ts) =>
ts.map((t) => {
if (t.id !== id) return t;
const i = Math.min(2, Math.max(0, ORDER.indexOf(t.status) + direction));
return { ...t, status: ORDER[i] };
}),
);
}
remove(id: number) {
this._tasks.update((ts) => ts.filter((t) => t.id !== id));
}
}Step 3: The task card
The card is a presentational component: it receives a task and emits events. It knows nothing about the store:
// src/app/task-card/task-card.ts
import { Component, ChangeDetectionStrategy, input, output } from '@angular/core';
import { Task } from '../board-store';
@Component({
selector: 'app-task-card',
changeDetection: ChangeDetectionStrategy.OnPush,
host: { '[class.high]': "task().priority === 'high'" },
template: `
<span class="title">{{ task().title }}</span>
<div class="actions">
@if (task().status !== 'todo') { <button (click)="move.emit(-1)">◀</button> }
@if (task().status !== 'done') { <button (click)="move.emit(1)">▶</button> }
<button (click)="remove.emit()">🗑</button>
</div>
`,
styles: `
:host { display: flex; justify-content: space-between; align-items: center; gap: 6px;
background: #fff; border: 1px solid #ddd; border-left: 4px solid #9e9e9e;
border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; font-size: 14px; }
:host(.high) { border-left-color: #dd0031; }
button { border: 0; background: none; cursor: pointer; padding: 2px; }
`,
})
export class TaskCard {
task = input.required<Task>();
move = output<1 | -1>();
remove = output<void>();
}Step 4: The add-task form
A small reactive form with validation. On submit it emits the new task data and resets itself:
// src/app/add-task-form/add-task-form.ts
import { Component, inject, output } from '@angular/core';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { Priority } from '../board-store';
@Component({
selector: 'app-add-task-form',
imports: [ReactiveFormsModule],
template: `
<form [formGroup]="form" (ngSubmit)="submit()">
<input formControlName="title" placeholder="New task…" />
<select formControlName="priority">
<option value="low">Low</option>
<option value="high">High</option>
</select>
<button [disabled]="form.invalid">Add</button>
</form>
`,
})
export class AddTaskForm {
added = output<{ title: string; priority: Priority }>();
form = inject(FormBuilder).nonNullable.group({
title: ['', [Validators.required, Validators.minLength(3)]],
priority: ['low' as Priority],
});
submit() {
this.added.emit(this.form.getRawValue());
this.form.reset();
}
}Step 5: The board
The root component connects the store to the UI. It is the only component that injects BoardStore — a clean "smart parent, presentational children" split:
// src/app/app.ts
import { Component, inject } from '@angular/core';
import { BoardStore } from './board-store';
import { TaskCard } from './task-card/task-card';
import { AddTaskForm } from './add-task-form/add-task-form';
@Component({
selector: 'app-root',
imports: [TaskCard, AddTaskForm],
template: `
<header>
<h1>Task Board</h1>
<span>{{ store.progress() }}% done</span>
</header>
<app-add-task-form (added)="store.add($event.title, $event.priority)" />
<input class="filter" placeholder="Filter…" (input)="store.filter.set($any($event.target).value)" />
<div class="columns">
@for (col of store.columns(); track col.status) {
<section>
<h2>{{ labels[col.status] }} ({{ col.tasks.length }})</h2>
@for (t of col.tasks; track t.id) {
<app-task-card [task]="t" (move)="store.move(t.id, $event)" (remove)="store.remove(t.id)" />
} @empty {
<p class="empty">Nothing here</p>
}
</section>
}
</div>
`,
styleUrl: './app.css',
})
export class App {
protected store = inject(BoardStore);
protected labels = { todo: 'To do', doing: 'Doing', done: 'Done' };
}And the board's stylesheet:
/* src/app/app.css */
header { display: flex; justify-content: space-between; align-items: center;
background: #dd0031; color: #fff; padding: 10px 16px; }
h1 { font-size: 20px; margin: 0; }
.filter { margin: 0 16px; width: calc(100% - 32px); }
.columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 16px; }
section { background: #ebecf0; border-radius: 8px; padding: 8px; min-height: 120px; }
h2 { font-size: 14px; margin: 0 0 8px; }
.empty { color: #888; font-style: italic; }Step 6: Test the store
Finally, a spec for the store's most important behaviour:
// src/app/board-store.spec.ts
import { TestBed } from '@angular/core/testing';
import { BoardStore } from './board-store';
describe('BoardStore', () => {
let store: BoardStore;
beforeEach(() => {
localStorage.clear();
store = TestBed.inject(BoardStore);
});
it('adds tasks to the To do column', () => {
store.add('Write docs', 'low');
expect(store.columns()[0].tasks.map((t) => t.title)).toEqual(['Write docs']);
});
it('moves a task forward but never past Done', () => {
store.add('Ship it', 'high');
const id = store.tasks()[0].id;
store.move(id, 1);
store.move(id, 1);
store.move(id, 1);
expect(store.tasks()[0].status).toBe('done');
expect(store.progress()).toBe(100);
});
});BoardStore
✔ adds tasks to the To do column
✔ moves a task forward but never past Done
Executed 2 of 2 SUCCESS
Ideas to extend the project
| Feature | Concepts you'll practise |
|---|---|
| Drag and drop between columns | Angular CDK DragDropModule |
| Edit a task's title inline | model(), two-way binding, (keyup.enter) |
A /task/:id detail page |
Routing, withComponentInputBinding() |
| Load tasks from a REST API | HttpClient, toSignal() or httpResource() |
| Lazy-load a statistics panel | @defer (on interaction) |
Tip: Notice how the presentational
TaskCardandAddTaskFormdon't know where data comes from. SwappinglocalStoragefor an HTTP backend only changesBoardStore.
Test yourself
Why does TaskCard emit move and remove events instead of injecting BoardStore itself?
- Components cannot inject services
- It keeps the card presentational and reusable; the parent decides what the events do
- Outputs are faster than services
- OnPush forbids injection
Which part of BoardStore keeps localStorage in sync with the tasks?
- The
columnscomputed - An
effect()that reads_tasks()and writes to storage - The
movemethod - The TaskCard component
Why does @for (t of col.tasks; track t.id) track by id?
- Ids are shorter than titles
- So Angular can reuse each card's DOM when tasks move or the list is filtered
- Because tasks are strings
- It is required for OnPush