To-do List with Signals - Mini Project
To-Do List Using Angular Signals
In this part, a simple To-Do List is created using Angular signals to practice how signals work in a real example.
The goal is to add tasks, display them in a list, and delete tasks using signals.
Task Signal Setup
A signal named tasks is created to store the list of tasks.
Each task is an object with id, title, and completed properties.
A separate signal is created to store the input value for a new task title.
Displaying the Task List
The task list is shown using Angular control flow with @for.
Since tasks is a signal, it is accessed using tasks().
If there are no tasks, “No Task found” is displayed using @empty.
Adding a New Task
An input field is used to type a task title.
The value is taken from the title signal.
The addTask() function adds a new task to the signal array.
Empty tasks are not added because of the if (this.title()) check.
After adding a task, the input field is cleared.
Deleting a Task
Each task has a delete button.
The task id is passed to the delete function.
The task is removed by filtering out the matching id.
Important Points
Tasks are stored in an array signal.
update() is used to add and remove tasks from the signal.
Signals are always accessed using () in the template.
Empty input values are prevented from being added.
@empty is used to show a message when the task list is empty.