Skip to content

Commit

Permalink
successfully added delete feature to the task manager
Browse files Browse the repository at this point in the history
  • Loading branch information
albindavidc committed Dec 31, 2024
1 parent 721862c commit 5503c4d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ <h3>{{ task().title }}</h3>
</p>
</form>
<p>
<button (onclick)="deleteTask()">Delete</button>
<button (click)="deleteTask()">Delete</button>
</p>
</article>
2 changes: 2 additions & 0 deletions src/app/tasks/tasks-list/task-item/task-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class TaskItemComponent {
}

deleteTask(): void {
console.log(`Task ID to delete: ${this.task().id}`);

this.delete.emit(this.task().id);
}
}
4 changes: 3 additions & 1 deletion src/app/tasks/tasks-list/tasks-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ <h2>My Tasks</h2>
<ul>
@for (task of tasks(); track task) {
<li>
<app-task-item [task]="task" />
<app-task-item [task]="task" (delete)="onDeleteTask($event)"/>

</li>

}
</ul>
5 changes: 4 additions & 1 deletion src/app/tasks/tasks-list/tasks-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, computed, inject, signal } from '@angular/core';
import { TaskItemComponent } from './task-item/task-item.component';
import { TasksService } from '../task.service';
import { CommonModule } from '@angular/common';

@Component({
selector: 'app-tasks-list',
imports: [TaskItemComponent],
imports: [CommonModule, TaskItemComponent],
templateUrl: './tasks-list.component.html',
styleUrl: './tasks-list.component.css',
})
Expand Down Expand Up @@ -36,6 +37,8 @@ export class TasksListComponent {
}

onDeleteTask(taskId: string): void {
console.log(`Deleting task with ID: ${taskId}`);

this.tasksService.deleteTasks(taskId);
}
}

0 comments on commit 5503c4d

Please sign in to comment.