From ae322a38fbfce2439f282fd78e74a583b48510aa Mon Sep 17 00:00:00 2001 From: Maxime Delporte Date: Tue, 22 Apr 2025 07:36:25 -0300 Subject: [PATCH] Using Dependency Injection inside task.component instead of using Output for tasks.components. --- src/app/tasks/task/task.component.ts | 7 ++++--- src/app/tasks/tasks.component.html | 5 +---- src/app/tasks/tasks.component.ts | 5 ----- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/app/tasks/task/task.component.ts b/src/app/tasks/task/task.component.ts index a207e10..39ecc4e 100644 --- a/src/app/tasks/task/task.component.ts +++ b/src/app/tasks/task/task.component.ts @@ -1,7 +1,8 @@ -import {Component, EventEmitter, Input, Output} from '@angular/core'; +import {Component, EventEmitter, inject, Input, Output} from '@angular/core'; import {Task} from './task.model'; import {CardComponent} from '../../shared/card/card.component'; import {DatePipe} from '@angular/common'; +import {TasksService} from '../tasks.service'; @Component({ selector: 'app-task', @@ -14,9 +15,9 @@ import {DatePipe} from '@angular/common'; }) export class TaskComponent { @Input({ required: true }) task!: Task; - @Output() complete = new EventEmitter(); + tasksService = inject(TasksService); onCompleteTask() { - this.complete.emit(this.task.id); + this.tasksService.removeTask(this.task.id); } } diff --git a/src/app/tasks/tasks.component.html b/src/app/tasks/tasks.component.html index 20e972e..020886b 100644 --- a/src/app/tasks/tasks.component.html +++ b/src/app/tasks/tasks.component.html @@ -17,10 +17,7 @@ diff --git a/src/app/tasks/tasks.component.ts b/src/app/tasks/tasks.component.ts index 4538cbd..d38405a 100644 --- a/src/app/tasks/tasks.component.ts +++ b/src/app/tasks/tasks.component.ts @@ -1,6 +1,5 @@ import {Component, Input} from '@angular/core'; import {type User} from '../user/user.model'; -import {type NewTaskData, type Task} from './task/task.model'; import {TaskComponent} from './task/task.component'; import {NewTaskComponent} from './new-task/new-task.component'; import {TasksService} from './tasks.service'; @@ -21,10 +20,6 @@ export class TasksComponent { return this.tasksService.getUserTasks(this.user.id); } - onCompleteTask(taskId: string) { - this.tasksService.removeTask(taskId); - } - onStartAddTask() { this.isAddingTask = true; }