Using dependency injection inside new-task.component.
All checks were successful
Deploying Website / build (push) Successful in 1m3s

This commit is contained in:
Maxime Delporte 2025-04-22 07:14:12 -03:00
parent b3d2a49ec9
commit 73de5fedfe
3 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,7 @@
import {Component, EventEmitter, Output} from '@angular/core';
import {Component, EventEmitter, inject, Input, Output} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {NewTaskData} from '../task/task.model';
import {TasksService} from '../tasks.service';
@Component({
selector: 'app-new-task',
@ -11,22 +12,28 @@ import {NewTaskData} from '../task/task.model';
styleUrl: './new-task.component.css'
})
export class NewTaskComponent {
@Output() cancel = new EventEmitter<void>();
@Output() add = new EventEmitter<NewTaskData>();
@Input({required: true}) userId!: string;
@Output() close = new EventEmitter<void>();
enteredTitle = '';
enteredSummary = '';
enteredDate = '';
tasksService = inject(TasksService);
onCancel() {
this.cancel.emit();
this.close.emit();
}
onSubmit() {
let taskContent: NewTaskData = {
let taskData: NewTaskData = {
title: this.enteredTitle,
summary: this.enteredSummary,
date: this.enteredDate,
};
this.add.emit(taskContent);
this.tasksService.addTaskFor(this.userId, taskData);
this.close.emit()
}
}

View File

@ -1,7 +1,7 @@
@if (isAddingTask) {
<app-new-task
(cancel)="onCancelAddTask()"
(add)="onAddTask($event)"
[userId]="user.id"
(close)="onCloseAddTask()"
/>
}

View File

@ -29,12 +29,7 @@ export class TasksComponent {
this.isAddingTask = true;
}
onCancelAddTask() {
onCloseAddTask() {
this.isAddingTask = false;
}
onAddTask(taskData: NewTaskData) {
this.tasksService.addTaskFor(this.user.id, taskData);
this.onCancelAddTask()
}
}