Todo List (Standalone Component with @for)

easy
By FrontendAtlas Editorial · Updated Nov 12, 2026
easy level
Standalone component setupSignal state for the input text and the todo listRendering lists with @for and an explicit track expressionUsing [(ngModel)] for simple form input bindingBasic UX for add / toggle / remove actions
Build a small todo list using an Angular standalone component. Add tasks, mark them complete, remove them, and render stable list identity with modern @for (...; track ...) control flow.

Requirements

  • Use a standalone Angular component as the root component.
  • Display a text input and an "Add" button for creating new todos.
  • Render todo items with @for and track todo.id, so each row keeps its identity.
  • Each todo item should show a label and a checkbox to toggle completion.
  • Allow removing a single todo item from the list.
  • Optionally provide a "Clear completed" action to remove all completed todos.

What the checks look for

The checks find elements by listitem, textbox, button "Add", checkbox, button "Remove". Keep these in your markup.

Expected behavior

  • Typing a non-empty value and clicking "Add" appends a new todo to the list and clears the input.
  • Empty or whitespace-only values are ignored (no item is added).
  • Clicking a todo’s checkbox toggles its completed state.
  • Completed todos are visually distinguished (e.g. line-through).
  • Clicking a remove button deletes that specific todo.
  • If you implement "Clear completed", it removes only the completed todos.

Implementation notes

  • Keep everything in AppComponent (src/app/app.component.ts and app.component.html). No extra services or components are required.
  • Store the todos as an array of { id, text, done } objects. Holding the array in a signal and replacing it on every change (todos.update(...)) keeps anything computed from it correct.
  • Use @for with track todo.id so item identity stays stable without a separate tracking function.
  • Use [(ngModel)] for the input binding (remember to import FormsModule); it binds to a signal as well as to a plain field.
  • Use click handlers like (click)="addTask()" and (click)="removeTask(todo)" to change the list.

Solution idea

This exercise models a classic todo list in a single standalone component. The input text lives in a newTask signal bound with [(ngModel)], and the list lives in a todos signal holding { id, text, done } objects. hasTodos is computed from the list and switches between the list and the empty state. The template renders @for (todo of todos(); track todo.id), and every handler replaces the array through todos.update(...) instead of editing it in place.