Project 1: Todo App with Signals and Local Storage

Angular 18 min min read Updated: Nov 16, 2026 Beginner
Project 1: Todo App with Signals and Local Storage
Beginner Topic 1 of 4

What We Build

  • Add, complete, edit and delete todos
  • Filter: All, Active, Completed
  • Show how many items are left
  • Save to localStorage so data stays after refresh
bash g new todo-app --style=css --ssr=false cd todo-app ng generate service todo-store ng generate component todo-list ng generate component todo-item ng serve

Step 1: Model

typescript // src/app/todo.model.ts export interface Todo { id: number; title: string; done: boolean; } export type Filter = 'all' | 'active' | 'done';

Step 2: Store Service

typescript // src/app/todo-store.ts import { Injectable, computed, effect, signal } from '@angular/core'; import { Filter, Todo } from './todo.model'; const KEY = 'todos-v1'; @Injectable({ providedIn: 'root' }) export class TodoStore { private _todos = signal<Todo[]>(this.load()); filter = signal<Filter>('all'); todos = this._todos.asReadonly(); visible = computed(() => { const f = this.filter(); return this._todos().filter(t => f === 'all' || (f === 'done' ? t.done : !t.done)); }); remaining = computed(() => this._todos().filter(t => !t.done).length); hasDone = computed(() => this._todos().some(t => t.done)); constructor() { effect(() => localStorage.setItem(KEY, JSON.stringify(this._todos()))); // auto-save } add(title: string) { const clean = title.trim(); if (!clean) return; this._todos.update(list => [...list, { id: Date.now(), title: clean, done: false }]); } toggle(id: number) { this._todos.update(list => list.map(t => (t.id === id ? { ...t, done: !t.done } : t))); } rename(id: number, title: string) { this._todos.update(list => list.map(t => (t.id === id ? { ...t, title: title.trim() } : t))); } remove(id: number) { this._todos.update(list => list.filter(t => t.id !== id)); } clearDone() { this._todos.update(list => list.filter(t => !t.done)); } toggleAll(done: boolean) { this._todos.update(list => list.map(t => ({ ...t, done }))); } private load(): Todo[] { try { return JSON.parse(localStorage.getItem(KEY) ?? '[]'); } catch { return []; } } }

Step 3: Item Component

typescript // todo-item.ts @Component({ selector: 'app-todo-item', changeDetection: ChangeDetectionStrategy.OnPush, templateUrl: './todo-item.html', styleUrl: './todo-item.css', }) export class TodoItem { todo = input.required<Todo>(); toggle = output<void>(); remove = output<void>(); rename = output<string>(); editing = signal(false); save(value: string) { this.editing.set(false); if (value.trim() && value !== this.todo().title) this.rename.emit(value); } }
html <!-- todo-item.html --> <li [class.done]="todo().done"> <input type="checkbox" [checked]="todo().done" (change)="toggle.emit()" [attr.aria-label]="'Complete ' + todo().title"> @if (editing()) { <input #edit class="edit" [value]="todo().title" (blur)="save(edit.value)" (keydown.enter)="save(edit.value)" (keydown.escape)="editing.set(false)"> } @else { <span (dblclick)="editing.set(true)">{{ todo().title }}</span> } <button (click)="remove.emit()" aria-label="Delete">&times;</button> </li>

Step 4: List Component

typescript // todo-list.ts @Component({ selector: 'app-todo-list', imports: [TodoItem], templateUrl: './todo-list.html', styleUrl: './todo-list.css', }) export class TodoList { store = inject(TodoStore); filters: Filter[] = ['all', 'active', 'done']; add(input: HTMLInputElement) { this.store.add(input.value); input.value = ''; } }
html <!-- todo-list.html --> <section class="todo"> <h1>My Todos</h1> <input #newTodo placeholder="What needs to be done?" (keydown.enter)="add(newTodo)" autofocus> <ul> @for (t of store.visible(); track t.id) { <app-todo-item [todo]="t" (toggle)="store.toggle(t.id)" (remove)="store.remove(t.id)" (rename)="store.rename(t.id, $event)" /> } @empty { <li class="empty">Nothing here. Add your first todo!</li> } </ul> <footer> <span>{{ store.remaining() }} item{{ store.remaining() === 1 ? '' : 's' }} left</span> <nav> @for (f of filters; track f) { <button [class.active]="store.filter() === f" (click)="store.filter.set(f)">{{ f }}</button> } </nav> @if (store.hasDone()) { <button (click)="store.clearDone()">Clear completed</button> } </footer> </section>

Step 5: Show It and Style It

typescript // app.ts @Component({ selector: 'app-root', imports: [TodoList], template: `<app-todo-list />` }) export class App {}
css .todo { max-width: 480px; margin: 40px auto; font-family: system-ui, sans-serif; } ul { list-style: none; padding: 0; } li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid #eee; } li.done span { text-decoration: line-through; color: #888; } button.active { font-weight: bold; text-decoration: underline; } footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

What You Practiced

  • Signals and computed for derived data
  • effect for saving
  • input() and output() for component communication
  • @for, @if and @empty
  • Immutable updates

Extend It

  • Due dates and priority
  • Drag and drop with @angular/cdk/drag-drop
  • Sync with a server using HttpClient
  • Unit tests for TodoStore

Conclusion

The todo app combines components, a signal store, computed values and automatic saving. These same ideas power much larger apps.

Quick Summary: TodoStore with signals + item/list components + effect saves to localStorage.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators